Add regression test minimized from async-std write

This commit is contained in:
David Tolnay 2022-07-24 11:06:54 -07:00
parent c32dcbba18
commit cb0ed1bdae
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 67 additions and 0 deletions

View File

@ -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;
}

View File

@ -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`.