Skip to content

Hint about a moved value in nested closure #41482

Closed
@antoyo

Description

@antoyo

Hello.
In the following code:

fn main() {
    let mut vec = vec![1];
    let vec2 = vec![1];
    let vec3 = vec![1];
    vec2.iter().map(move |_| {
        vec3.iter().map(move |_| {
            vec.iter();
            0
        });
        0
    });
}

we get the following error:

error[E0507]: cannot move out of captured outer variable in an `FnMut` closure
 --> src/main.rs:6:25
  |
6 |         vec3.iter().map(move |_| {
  |                         ^^^^^^^^ cannot move out of captured outer variable in an `FnMut` closure

which is not very helpful as it does not indicate which variable it is.
It would be nice to have a better hint in this case.
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions