Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Awaiting on Pin<Box<dyn Future>> causes ICE #1317

Closed
KamilaBorowska opened this issue Apr 10, 2020 · 3 comments
Closed

Awaiting on Pin<Box<dyn Future>> causes ICE #1317

KamilaBorowska opened this issue Apr 10, 2020 · 3 comments

Comments

@KamilaBorowska
Copy link

The following program causes an ICE when ran with cargo miri:

use std::{
    future::Future,
    pin::Pin,
    task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};

pub fn block_on<F: Future>(mut future: F) -> F::Output {
    let mut future = unsafe { Pin::new_unchecked(&mut future) };

    static VTABLE: RawWakerVTable = RawWakerVTable::new(
        |_| unimplemented!("clone"),
        |_| unimplemented!("wake"),
        |_| unimplemented!("wake_by_ref"),
        |_| (),
    );
    let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
    let mut context = Context::from_waker(&waker);

    loop {
        if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
            break val;
        }
    }
}

fn main() {
    block_on(async {
        let boxed: Pin<Box<dyn Future<Output = ()>>> = Box::pin(async {});
        boxed.await;
    });
}

Error message:

error: internal compiler error: src/librustc_mir/interpret/place.rs:231: vtable not supported on type std::pin::Pin<&mut dyn std::future::Future<Output = ()>>

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:880:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.44.0-nightly (94d346360 2020-04-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z always-encode-mir -Z mir-emit-retag -Z mir-opt-level=0 -C debug-assertions=on -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden
@RalfJung
Copy link
Member

Thanks for the report! I think this is a duplicate of #1038. Could you confirm?

@KamilaBorowska
Copy link
Author

KamilaBorowska commented Apr 10, 2020

It's panicking in a different place (place.rs:258:9 and place.rs:231), and the error message is different ("called Result::unwrap() on an Err value" and "vtable not supported on type"), this was tested with the same nightly (2020-04-09). The issues seem very similar, both involve calling a method on Pin<&mut dyn Trait> but I'm not sure whether it's a duplicate.

@RalfJung
Copy link
Member

RalfJung commented Apr 10, 2020

Hm, good point.

I looked a bit more into this, and I think the difference is because builtin_deref still works in your case, but then .vtable() on the result fails. That's probably because there is a Box here but Rc in the other example.

Still, both seem about dyn Trait with pointer types other than Box, &, &mut, so I'll close this as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants