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

Attempting to run an async fn after completion mentions generators #65419

Open
Nemo157 opened this issue Oct 14, 2019 · 7 comments

Comments

@Nemo157
Copy link
Contributor

@Nemo157 Nemo157 commented Oct 14, 2019

If a user attempts to do something like this (playground including trivial executor):

async fn foo() {
}

fn main() {
    let mut future = Box::pin(foo());
    executor::block_on(future.as_mut());
    executor::block_on(future.as_mut());
}

they get a panic talking about generators:

thread 'main' panicked at 'generator resumed after completion', src/main.rs:1:16

This issue has been assigned to @ninjasource via this comment.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis commented Oct 15, 2019

Hey @Zoxc -- where does this error come from, anyway? A quick ripgrep of the source didn't find an obvious source.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis commented Oct 15, 2019

Is it from the Display impl for PanicInfo?

@Zoxc

This comment has been minimized.

Copy link
Contributor

@Zoxc Zoxc commented Oct 15, 2019

Yeah that's it.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis commented Oct 15, 2019

OK, yes, that's what I meant. So to fix this we presumably want to:

  • Add a new PanicInfo variant with a different description
  • Use that PanicInfo variant for generators that arose from async fn

We would need to get access to the generator_kind for this generator in this function here;

fn create_generator_resume_function<'tcx>(
tcx: TyCtxt<'tcx>,
transform: TransformVisitor<'tcx>,
def_id: DefId,
source: MirSource<'tcx>,
body: &mut Body<'tcx>,
) {

Right now, I don't think that is stored in the MIR, but we could easily do do (I'd rather not retrieve it from the HIR).

Sound about right?

@ninjasource

This comment has been minimized.

Copy link

@ninjasource ninjasource commented Oct 22, 2019

@rustbot claim

@rustbot rustbot self-assigned this Oct 22, 2019
@ninjasource

This comment has been minimized.

Copy link

@ninjasource ninjasource commented Oct 22, 2019

Hi @nikomatsakis, that makes sense. I'll lean on @gilescope for initial guidance on this and I'll add more comments after I dig a little deeper. Cheers, David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.