]> git.lizzy.rs Git - rust.git/blob - tests/ui/async-await/issue-73137.rs
Rollup merge of #107108 - sulami:issue-83968-doc-alias-typo-suggestions, r=compiler...
[rust.git] / tests / ui / async-await / issue-73137.rs
1 // Regression test for <https://github.com/rust-lang/rust/issues/73137>
2
3 // run-pass
4 // edition:2018
5 // revisions: normal drop-tracking
6 // [normal]compile-flags: -Zdrop-tracking=no
7 // [drop-tracking]compile-flags: -Zdrop-tracking
8
9 #![allow(dead_code)]
10 use std::future::Future;
11 use std::task::{Waker, Wake, Context};
12 use std::sync::Arc;
13
14 struct DummyWaker;
15 impl Wake for DummyWaker {
16     fn wake(self: Arc<Self>) {}
17 }
18
19 struct Foo {
20     a: usize,
21     b: &'static u32,
22 }
23
24 #[inline(never)]
25 fn nop<T>(_: T) {}
26
27 fn main() {
28     let mut fut = Box::pin(async {
29         let action = Foo {
30             b: &42,
31             a: async { 0 }.await,
32         };
33
34         // An error in the generator transform caused `b` to be overwritten with `a` when `b` was
35         // borrowed.
36         nop(&action.b);
37         assert_ne!(0usize, unsafe { std::mem::transmute(action.b) });
38
39         async {}.await;
40     });
41     let waker = Waker::from(Arc::new(DummyWaker));
42     let mut cx = Context::from_waker(&waker);
43     let _ = fut.as_mut().poll(&mut cx);
44 }