Skip to content
Myr

Merge pull request #187 from dtolnay/temporaries

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

Drop temporaries as early as possible in $:expr case

authored by David Tolnay · committed by GitHub · parents fb3e4b7, 38591a9 · Browse files · 3 files+14 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

3 files+14 added−3 removed

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

3 files+14 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`
modified:tests/test_macros.rs+9 added
8 unmodified lines
9mod common;1011use self::common::*;12use anyhow::{anyhow, ensure};13use std::cell::Cell;14use std::future;1516#[test]17fn test_messages() {
43 unmodified lines
61 // semicolon, which is on the other side of the await point, making the62 // enclosing future non-Send.63 future::ready(anyhow!("...")).await;64 });6566 fn message(cell: Cell<&str>) -> &str {67 cell.get()68 }6970 require_send_sync(async {71 future::ready(anyhow!(message(Cell::new("...")))).await;72 });73}7475#[test]76fn test_brace_escape() {
3 unmodified lines