]> git.proxmox.com Git - rustc.git/blob - src/test/ui/async-await/issue-73137.rs
New upstream version 1.45.0+dfsg1
[rustc.git] / src / test / 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
6 #![allow(dead_code)]
7 #![feature(wake_trait)]
8 use std::future::Future;
9 use std::task::{Waker, Wake, Context};
10 use std::sync::Arc;
11
12 struct DummyWaker;
13 impl Wake for DummyWaker {
14 fn wake(self: Arc<Self>) {}
15 }
16
17 struct Foo {
18 a: usize,
19 b: &'static u32,
20 }
21
22 #[inline(never)]
23 fn nop<T>(_: T) {}
24
25 fn main() {
26 let mut fut = Box::pin(async {
27 let action = Foo {
28 b: &42,
29 a: async { 0 }.await,
30 };
31
32 // An error in the generator transform caused `b` to be overwritten with `a` when `b` was
33 // borrowed.
34 nop(&action.b);
35 assert_ne!(0usize, unsafe { std::mem::transmute(action.b) });
36
37 async {}.await;
38 });
39 let waker = Waker::from(Arc::new(DummyWaker));
40 let mut cx = Context::from_waker(&waker);
41 let _ = fut.as_mut().poll(&mut cx);
42 }