File: issue-73137.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,245,420 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (41 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Regression test for <https://github.com/rust-lang/rust/issues/73137>

//@ run-pass
//@ edition:2018

#![allow(dead_code)]
use std::future::Future;
use std::task::{Waker, Wake, Context};
use std::sync::Arc;

struct DummyWaker;
impl Wake for DummyWaker {
    fn wake(self: Arc<Self>) {}
}

struct Foo {
    a: usize,
    b: &'static u32,
}

#[inline(never)]
fn nop<T>(_: T) {}

fn main() {
    let mut fut = Box::pin(async {
        let action = Foo {
            b: &42,
            a: async { 0 }.await,
        };

        // An error in the coroutine transform caused `b` to be overwritten with `a` when `b` was
        // borrowed.
        nop(&action.b);
        assert_ne!(0usize, unsafe { std::mem::transmute(action.b) });

        async {}.await;
    });
    let waker = Waker::from(Arc::new(DummyWaker));
    let mut cx = Context::from_waker(&waker);
    let _ = fut.as_mut().poll(&mut cx);
}