diff --git a/src/test/ui/macros/format-args-temporaries-async.rs b/src/test/ui/macros/format-args-temporaries-async.rs new file mode 100644 index 00000000000..fc2e5e2190f --- /dev/null +++ b/src/test/ui/macros/format-args-temporaries-async.rs @@ -0,0 +1,40 @@ +// FIXME: check-pass +// check-fail +// edition:2021 + +use std::fmt::{self, Display}; +use std::future::Future; +use std::io; +use std::pin::Pin; +use std::task::{Context, Poll}; + +struct AsyncStdout; + +impl AsyncStdout { + fn write_fmt<'a>(&'a mut self, _args: fmt::Arguments) -> WriteFmtFuture<'a, Self> + where + Self: Unpin, + { + WriteFmtFuture(self) + } +} + +struct WriteFmtFuture<'a, T>(&'a mut T); + +impl<'a, T> Future for WriteFmtFuture<'a, T> { + type Output = io::Result<()>; + fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll { + unimplemented!() + } +} + +async fn async_main() { + let _write = write!(&mut AsyncStdout, "...").await; + //~^ ERROR temporary value dropped while borrowed + let _writeln = writeln!(&mut AsyncStdout, "...").await; + //~^ ERROR temporary value dropped while borrowed +} + +fn main() { + let _ = async_main; +} diff --git a/src/test/ui/macros/format-args-temporaries-async.stderr b/src/test/ui/macros/format-args-temporaries-async.stderr new file mode 100644 index 00000000000..73019d7eb6e --- /dev/null +++ b/src/test/ui/macros/format-args-temporaries-async.stderr @@ -0,0 +1,27 @@ +error[E0716]: temporary value dropped while borrowed + --> $DIR/format-args-temporaries-async.rs:32:30 + | +LL | let _write = write!(&mut AsyncStdout, "...").await; + | ------------^^^^^^^^^^^-------- + | | | + | | creates a temporary which is freed while still in use + | temporary value is freed at the end of this statement + | borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error[E0716]: temporary value dropped while borrowed + --> $DIR/format-args-temporaries-async.rs:34:34 + | +LL | let _writeln = writeln!(&mut AsyncStdout, "...").await; + | --------------^^^^^^^^^^^-------- + | | | + | | creates a temporary which is freed while still in use + | temporary value is freed at the end of this statement + | borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0716`.