Skip to content

Commit

Permalink
Drop temporaries as early as possible in $:expr case
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 4, 2021
1 parent 45f6545 commit 38591a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ macro_rules! anyhow {
});
($err:expr $(,)?) => ({
use $crate::private::kind::*;
match $err {
let error = match $err {
error => (&error).anyhow_kind().new(error),
}
};
error
});
($fmt:expr, $($arg:tt)*) => {
$crate::Error::msg($crate::private::format!($fmt, $($arg)*))
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/temporary-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ error[E0716]: temporary value dropped while borrowed
--> tests/ui/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
| temporary value is freed at the end of this statement
| argument requires that borrow lasts for `'static`

0 comments on commit 38591a9

Please sign in to comment.