From da60588d02f9b1381a21cb915803deaec671531f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 8 Oct 2019 17:41:25 -0700 Subject: [PATCH] Fix anyhow_kind dispatch on owned value --- src/kind.rs | 2 +- src/lib.rs | 2 +- tests/test_source.rs | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/kind.rs b/src/kind.rs index 1789a62..9a8a911 100644 --- a/src/kind.rs +++ b/src/kind.rs @@ -42,7 +42,7 @@ // #[allow(unused_imports)] // use $crate::private::{AdhocKind, TraitKind}; // let error = $msg; -// error.anyhow_kind().new(error) +// (&error).anyhow_kind().new(error) use crate::Error; use std::error::Error as StdError; diff --git a/src/lib.rs b/src/lib.rs index 11859d3..2f18b7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -404,7 +404,7 @@ macro_rules! anyhow { #[allow(unused_imports)] use $crate::private::{AdhocKind, TraitKind}; let error = $err; - error.anyhow_kind().new(error) + (&error).anyhow_kind().new(error) }); ($fmt:expr, $($arg:tt)*) => { $crate::private::new_adhoc(format!($fmt, $($arg)*)) diff --git a/tests/test_source.rs b/tests/test_source.rs index 6b35807..04e9a9a 100644 --- a/tests/test_source.rs +++ b/tests/test_source.rs @@ -35,6 +35,10 @@ fn test_variable_source() { let msg = "oh no!"; let error = anyhow!(msg); assert!(error.source().is_none()); + + let msg = msg.to_owned(); + let error = anyhow!(msg); + assert!(error.source().is_none()); } #[test]