PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: dtolnay/anyhow (rust)

Issue:
Usage of `bail!(error)` loses the context of `error`
I was in a situation recently where I was doing:

```rust
match some_result {
    Ok(()) => {}
    Err(e) => {
        if !err_is_ok(e) {
            bail!(e);
        }
    }
}
```

in this case `e` was actually of type `anyhow::Error` so a `return Err(e)` would have worked just fine, but I was surprised when this `bail!()` lost the context of the error of `e`, presumably because it called `.to_string()` on the result and lost all the context information.

Pull request:
Handle anyhow::Error as argument to anyhow!()
Fixes #46.

Patch:
diff --git a/src/kind.rs b/src/kind.rs
index 9a8a911..be9d9f4 100644
--- a/src/kind.rs
+++ b/src/kind.rs
@@ -45,7 +45,6 @@
 //     (&error).anyhow_kind().new(error)
 
 use crate::Error;
-use std::error::Error as StdError;
 use std::fmt::{Debug, Display};
 
 #[cfg(backtrace)]
@@ -80,13 +79,13 @@ pub trait TraitKind: Sized {
     }
 }
 
-impl<T> TraitKind for T where T: StdError + Send + Sync + 'static {}
+impl<E> TraitKind for E where E: Into<Error> {}
 
 impl Trait {
     pub fn new<E>(self, error: E) -> Error
     where
-        E: StdError + Send + Sync + 'static,
+        E: Into<Error>,
     {
-        Error::from_std(error, backtrace!())
+        error.into()
     }
 }


Test patch:
diff --git a/tests/test_source.rs b/tests/test_source.rs
index 04e9a9a..018267d 100644
--- a/tests/test_source.rs
+++ b/tests/test_source.rs
@@ -53,3 +53,10 @@ fn test_io_source() {
     let error = anyhow!(TestError::Io(io));
     assert_eq!("oh no!", error.source().unwrap().to_string());
 }
+
+#[test]
+fn test_anyhow_from_anyhow() {
+    let error = anyhow!("oh no!").context("context");
+    let error = anyhow!(error);
+    assert_eq!("oh no!", error.source().unwrap().to_string());
+}