Skip to content

Confusing note "use occurs due to use in closure" #89191

@camelid

Description

@camelid

Ideally, it would say something like "value used here in closure".

Code

playground

fn main() {
    let x = vec![42];
    let _y = x;
    let _f = || { x; };
}

Output

error[E0382]: use of moved value: `x`
 --> src/main.rs:4:14
  |
2 |     let x = vec![42];
  |         - move occurs because `x` has type `Vec<i32>`, which does not implement the `Copy` trait
3 |     let _y = x;
  |              - value moved here
4 |     let _f = || { x; };
  |              ^^   - use occurs due to use in closure
  |              |
  |              value used here after move

Meta

This seems to have regressed a while ago, in Rust 1.36.0. In Rust 1.35.0, the error looked like this:

error[E0382]: capture of moved value: `x`
 --> <source>:4:19
  |
3 |     let _y = x;
  |         -- value moved here
4 |     let _f = || { x; };
  |                   ^ value captured here after move
  |
  = note: move occurs because `x` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions