Skip to content

Compiler does not suggest move when it would be appropriate #56093

Description

@grantslatton

This snippet does not compile with the following error:

pub fn main() {
    |i: u32| { || i };
}

error[E0597]: `i` does not live long enough
 --> src/main.rs:2:19
  |
2 |     |i: u32| { || i };
  |                -- ^ - borrowed value dropped before borrower
  |                |  |
  |                |  borrowed value does not live long enough
  |                capture occurs here
  |
  = note: values in a scope are dropped in the opposite order they are created

https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=2aa8b97e68b9eba4c1b7c0d3f627c386

But adding a move fixes it:

pub fn main() {
    |i: u32| { move || i };
}

I believe the compiler tries to suggest move where appropriate, and it seems that this case has been missed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed-by-NLLBugs fixed, but only when NLL is enabled.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions