Skip to content
Myr

Merge pull request #133 from dtolnay/temp

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

Improve error on temp value to point to the correct statement

authored by David Tolnay · committed by GitHub · parents f9419cd, 86dd074 · Browse files · 3 files+16 added−2 removed
This commit

State

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

Diff stats

3 files+16 added−2 removed

  • tests:+13 added−0 removed
  • other:+3 added−2 removed

3 files+16 added−2 removed

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