Skip to content

Commit

Permalink
Merge pull request #133 from dtolnay/temp
Browse files Browse the repository at this point in the history
Improve error on temp value to point to the correct statement
  • Loading branch information
dtolnay committed Dec 28, 2020
2 parents f9419cd + 86dd074 commit c1fa241
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/macros.rs
Expand Up @@ -173,8 +173,9 @@ macro_rules! anyhow {
};
($err:expr $(,)?) => ({
use $crate::private::kind::*;
let error = $err;
(&error).anyhow_kind().new(error)
match $err {
error => (&error).anyhow_kind().new(error),
}
});
($fmt:expr, $($arg:tt)*) => {
$crate::private::new_adhoc(format!($fmt, $($arg)*))
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/temporary-value.rs
@@ -0,0 +1,5 @@
use anyhow::anyhow;

fn main() {
let _ = anyhow!(&String::new());
}
8 changes: 8 additions & 0 deletions tests/ui/temporary-value.stderr
@@ -0,0 +1,8 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/temporary-value.rs:4:22
|
4 | let _ = anyhow!(&String::new());
| ---------^^^^^^^^^^^^^-- temporary value is freed at the end of this statement
| | |
| | creates a temporary which is freed while still in use
| argument requires that borrow lasts for `'static`

0 comments on commit c1fa241

Please sign in to comment.