Add ui test to reproduce non-Send panic temporary
This commit is contained in:
parent
3603a84a3d
commit
cbee2a1ec4
2 changed files with 46 additions and 0 deletions
19
tests/ui/macros/panic-temporaries.rs
Normal file
19
tests/ui/macros/panic-temporaries.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
// check-fail
|
||||||
|
// edition:2021
|
||||||
|
|
||||||
|
#![allow(unreachable_code)]
|
||||||
|
|
||||||
|
async fn f(_: u8) {}
|
||||||
|
|
||||||
|
async fn g() {
|
||||||
|
// Todo returns `!`, so the await is never reached, and in particular the
|
||||||
|
// temporaries inside the formatting machinery are not still alive at the
|
||||||
|
// await point.
|
||||||
|
f(todo!("...")).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn require_send(_: impl Send) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
require_send(g()); //~ future cannot be sent between threads safely
|
||||||
|
}
|
27
tests/ui/macros/panic-temporaries.stderr
Normal file
27
tests/ui/macros/panic-temporaries.stderr
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
error: future cannot be sent between threads safely
|
||||||
|
--> $DIR/panic-temporaries.rs:18:18
|
||||||
|
|
|
||||||
|
LL | require_send(g());
|
||||||
|
| ^^^ future returned by `g` is not `Send`
|
||||||
|
|
|
||||||
|
= help: the trait `Sync` is not implemented for `core::fmt::Opaque`
|
||||||
|
note: future is not `Send` as this value is used across an await
|
||||||
|
--> $DIR/panic-temporaries.rs:12:20
|
||||||
|
|
|
||||||
|
LL | f(todo!("...")).await;
|
||||||
|
| ------------ ^^^^^^ await occurs here, with `$crate::format_args!($($arg)+)` maybe used later
|
||||||
|
| |
|
||||||
|
| has type `ArgumentV1<'_>` which is not `Send`
|
||||||
|
note: `$crate::format_args!($($arg)+)` is later dropped here
|
||||||
|
--> $DIR/panic-temporaries.rs:12:26
|
||||||
|
|
|
||||||
|
LL | f(todo!("...")).await;
|
||||||
|
| ^
|
||||||
|
note: required by a bound in `require_send`
|
||||||
|
--> $DIR/panic-temporaries.rs:15:25
|
||||||
|
|
|
||||||
|
LL | fn require_send(_: impl Send) {}
|
||||||
|
| ^^^^ required by this bound in `require_send`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue