Skip to content

Generators require extra-long lifetime for return statement #44200

Closed
@alexcrichton

Description

@alexcrichton

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions