Fix anyhow_kind dispatch on owned value

This commit is contained in:
David Tolnay 2019-10-08 17:41:25 -07:00
parent d0c25a6b1c
commit da60588d02
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 6 additions and 2 deletions

View File

@ -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;

View File

@ -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)*))

View File

@ -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]