about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-07-24 11:06:54 -0700
committerDavid Tolnay <dtolnay@gmail.com>2022-07-24 11:11:39 -0700
commitcb0ed1bdaed082205c7da4375b78a112a0872ddf (patch)
tree870d9f2eca744b6fb49201bd4015188f0ac7a570
parentc32dcbba187d1ee0dbe92dc152cb9c2f3f42900c (diff)
downloadrust-cb0ed1bdaed082205c7da4375b78a112a0872ddf.tar.gz
rust-cb0ed1bdaed082205c7da4375b78a112a0872ddf.zip
Add regression test minimized from async-std write
-rw-r--r--src/test/ui/macros/format-args-temporaries-async.rs40
-rw-r--r--src/test/ui/macros/format-args-temporaries-async.stderr27
2 files changed, 67 insertions, 0 deletions
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<Self::Output> {
+        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`.