Skip to content

lint for unused lvalue statement #16502

Closed
@huonw

Description

@huonw
fn main() {
    let p = box 1i;

    let _ = p; // doesn't move
    p; // does move


    p; // error: use of moved value
}
<anon>:8:5: 8:6 error: use of moved value: `p`
<anon>:8     p;
             ^
<anon>:5:5: 5:6 note: `p` moved here because it has type `&mut int`, which is non-copyable (perhaps you meant to use clone()?)
<anon>:5     p; // does move
             ^

(Adapted from this question, using Box to avoid possible confusion from reborrowing of &mut.)

It seems strange that an unassigned useless path differs to a useless path assigned to _.

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-type-systemArea: Type systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.P-lowLow priorityT-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions