Skip to content

Commit b6121a5

Browse files
Add regression test for #73137
Co-authored-by: Aaron1011 <[email protected]>
1 parent c3b0b7b commit b6121a5

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

0 commit comments

Comments
 (0)