Skip to content

Commit cb0ed1b

Browse files
committed
Add regression test minimized from async-std write
1 parent c32dcbb commit cb0ed1b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// FIXME: check-pass
2+
// check-fail
3+
// edition:2021
4+
5+
use std::fmt::{self, Display};
6+
use std::future::Future;
7+
use std::io;
8+
use std::pin::Pin;
9+
use std::task::{Context, Poll};
10+
11+
struct AsyncStdout;
12+
13+
impl AsyncStdout {
14+
fn write_fmt<'a>(&'a mut self, _args: fmt::Arguments) -> WriteFmtFuture<'a, Self>
15+
where
16+
Self: Unpin,
17+
{
18+
WriteFmtFuture(self)
19+
}
20+
}
21+
22+
struct WriteFmtFuture<'a, T>(&'a mut T);
23+
24+
impl<'a, T> Future for WriteFmtFuture<'a, T> {
25+
type Output = io::Result<()>;
26+
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
27+
unimplemented!()
28+
}
29+
}
30+
31+
async fn async_main() {
32+
let _write = write!(&mut AsyncStdout, "...").await;
33+
//~^ ERROR temporary value dropped while borrowed
34+
let _writeln = writeln!(&mut AsyncStdout, "...").await;
35+
//~^ ERROR temporary value dropped while borrowed
36+
}
37+
38+
fn main() {
39+
let _ = async_main;
40+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/format-args-temporaries-async.rs:32:30
3+
|
4+
LL | let _write = write!(&mut AsyncStdout, "...").await;
5+
| ------------^^^^^^^^^^^--------
6+
| | |
7+
| | creates a temporary which is freed while still in use
8+
| temporary value is freed at the end of this statement
9+
| borrow later used here
10+
|
11+
= note: consider using a `let` binding to create a longer lived value
12+
13+
error[E0716]: temporary value dropped while borrowed
14+
--> $DIR/format-args-temporaries-async.rs:34:34
15+
|
16+
LL | let _writeln = writeln!(&mut AsyncStdout, "...").await;
17+
| --------------^^^^^^^^^^^--------
18+
| | |
19+
| | creates a temporary which is freed while still in use
20+
| temporary value is freed at the end of this statement
21+
| borrow later used here
22+
|
23+
= note: consider using a `let` binding to create a longer lived value
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0716`.

0 commit comments

Comments
 (0)