Skip to content

Generators require extra-long lifetime for return statement #44200

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

Closed
alexcrichton opened this issue Aug 31, 2017 · 4 comments
Closed

Generators require extra-long lifetime for return statement #44200

alexcrichton opened this issue Aug 31, 2017 · 4 comments
Labels
A-coroutines Area: Coroutines C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

When compiling:

#![feature(generators)]

fn main() {
    let _a = || {
        if false { yield }
        let a = String::new();
        a.len()
    };
}

I currently get:

error[E0597]: `a` does not live long enough
 --> foo.rs:8:5
  |
7 |         a.len()
  |         - borrow occurs here
8 |     };
  |     ^ `a` dropped here while still borrowed
9 | }
  | - borrowed value needs to live until here

error: aborting due to previous error

Would be nice to not have to bind it to a local!

@Zoxc
Copy link
Contributor

Zoxc commented Aug 31, 2017

They way interior types are being calculated is a bit crude. It just walks all the nodes and consider them live for the scope temporaries would be. a.len() contains an implicit borrow of a and being the last statement of a block it inherits the scope for temporaries from the parent, and that scope contains a yield. This is not really a bug, but we'd like to find a better way to calculate these types.

@Eroc33
Copy link

Eroc33 commented Aug 31, 2017

@Zoxc
Is this likely the same thing going on here? https://play.rust-lang.org/?gist=e472b9056ecc590837db32b17108bfd3&version=nightly

@Arnavion
Copy link

@Eroc33 Yes, see #44197

@shepmaster shepmaster added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2017
@alex
Copy link
Member

alex commented Sep 22, 2017

This appears to have been fixed by #44392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants