Add regression test minimized from async-std write
This commit is contained in:
parent
c32dcbba18
commit
cb0ed1bdae
2 changed files with 67 additions and 0 deletions
40
src/test/ui/macros/format-args-temporaries-async.rs
Normal file
40
src/test/ui/macros/format-args-temporaries-async.rs
Normal 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;
|
||||||
|
}
|
27
src/test/ui/macros/format-args-temporaries-async.stderr
Normal file
27
src/test/ui/macros/format-args-temporaries-async.stderr
Normal 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`.
|
Loading…
Add table
Add a link
Reference in a new issue