Skip to content

Error message for reuse of variable moved into a closure uses closure type instead of variable type #24357

Closed
@huonw

Description

@huonw
struct NoCopy;
fn main() {
   let x = NoCopy;
   let f = move || { let y = x; };
   let z = x;
}
<anon>:5:8: 5:9 error: use of moved value: `x`
<anon>:5    let z = x;
                ^
<anon>:4:17: 4:34 note: `x` moved into closure environment here because it has type `[closure(())]`, which is non-copyable
<anon>:4    let f = move || { let y = x; };
                         ^~~~~~~~~~~~~~~~~
<anon>:4:34: 4:34 help: perhaps you meant to use `clone()`?

Presumably the error message should say because it has type NoCopy which is non-copyable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)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