Skip to content

Commit cbee2a1

Browse files
committed
Add ui test to reproduce non-Send panic temporary
1 parent 3603a84 commit cbee2a1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/ui/macros/panic-temporaries.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-fail
2+
// edition:2021
3+
4+
#![allow(unreachable_code)]
5+
6+
async fn f(_: u8) {}
7+
8+
async fn g() {
9+
// Todo returns `!`, so the await is never reached, and in particular the
10+
// temporaries inside the formatting machinery are not still alive at the
11+
// await point.
12+
f(todo!("...")).await;
13+
}
14+
15+
fn require_send(_: impl Send) {}
16+
17+
fn main() {
18+
require_send(g()); //~ future cannot be sent between threads safely
19+
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: future cannot be sent between threads safely
2+
--> $DIR/panic-temporaries.rs:18:18
3+
|
4+
LL | require_send(g());
5+
| ^^^ future returned by `g` is not `Send`
6+
|
7+
= help: the trait `Sync` is not implemented for `core::fmt::Opaque`
8+
note: future is not `Send` as this value is used across an await
9+
--> $DIR/panic-temporaries.rs:12:20
10+
|
11+
LL | f(todo!("...")).await;
12+
| ------------ ^^^^^^ await occurs here, with `$crate::format_args!($($arg)+)` maybe used later
13+
| |
14+
| has type `ArgumentV1<'_>` which is not `Send`
15+
note: `$crate::format_args!($($arg)+)` is later dropped here
16+
--> $DIR/panic-temporaries.rs:12:26
17+
|
18+
LL | f(todo!("...")).await;
19+
| ^
20+
note: required by a bound in `require_send`
21+
--> $DIR/panic-temporaries.rs:15:25
22+
|
23+
LL | fn require_send(_: impl Send) {}
24+
| ^^^^ required by this bound in `require_send`
25+
26+
error: aborting due to previous error
27+

0 commit comments

Comments
 (0)