Skip to content
Myr

Drop temporaries as early as possible in $:expr case

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 45f6545 · Browse files · 2 files+5 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−3 removed

  • tests:+2 added−1 removed
  • other:+3 added−2 removed

2 files+5 added−3 removed

modified:src/macros.rs+3 added-2 removed
171 unmodified lines
172 error173 });174 ($err:expr $(,)?) => ({175 use $crate::private::kind::*;176 match $err {176 let error = match $err {177 error => (&error).anyhow_kind().new(error),178 }178 };179 error180 });181 ($fmt:expr, $($arg:tt)*) => {182 $crate::Error::msg($crate::private::format!($fmt, $($arg)*))183 };
1 unmodified line
modified:tests/ui/temporary-value.stderr+2 added-1 removed
1error[E0716]: temporary value dropped while borrowed2 --> tests/ui/temporary-value.rs:4:223 |44 | let _ = anyhow!(&String::new());5 | ---------^^^^^^^^^^^^^-- temporary value is freed at the end of this statement5 | ---------^^^^^^^^^^^^^-6 | | |7 | | creates a temporary which is freed while still in use8 | temporary value is freed at the end of this statement9 | argument requires that borrow lasts for `'static`