]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/async-is-unwindsafe.rs
Rollup merge of #107027 - GuillaumeGomez:rm-extra-removal, r=tmiasko
[rust.git] / tests / ui / async-await / async-is-unwindsafe.rs
1 // edition:2018
2
3 fn is_unwindsafe(_: impl std::panic::UnwindSafe) {}
4
5 fn main() {
6     // A normal future created by an async block takes a `&mut Context<'_>` argument.
7     // That should not leak through to the whole async block.
8     is_unwindsafe(async {
9         async {}.await; // this needs an inner await point
10     });
11
12     is_unwindsafe(async {
13         //~^ ERROR the type `&mut Context<'_>` may not be safely transferred across an unwind boundary
14         use std::ptr::null;
15         use std::task::{Context, RawWaker, RawWakerVTable, Waker};
16         let waker = unsafe {
17             Waker::from_raw(RawWaker::new(
18                 null(),
19                 &RawWakerVTable::new(|_| todo!(), |_| todo!(), |_| todo!(), |_| todo!()),
20             ))
21         };
22         let mut cx = Context::from_waker(&waker);
23         let cx_ref = &mut cx;
24
25         async {}.await; // this needs an inner await point
26
27         // in this case, `&mut Context<'_>` is *truly* alive across an await point
28         drop(cx_ref);
29     });
30 }