Skip to content

lint suggestion: unnecessary_move #11721

Open

Description

What it does

Lints against uses of move before a closure or async block that captures nothing by reference. 

Advantage

This is likely the result of a mistake from the implementer, which does not have the proper intuition about how closure borrow their contents. Sometimes it can be hard to reason about it.

For example the developer might not realise that a capture that is passed by value is always captured by value.

Drawbacks

No response

Example

    let a = String::new();
    let closure = move || {
        drop(a);  
    };

Could be written as:

    let a = String::new();
    let closure = || {
        drop(a);  
    };

Because the String is always captured by value, since it needs to be passed by value to drop.

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

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions