Skip to content

variable bindings in for loop are not linted as unused when unused #16335

Closed
@huonw

Description

@huonw
fn main() {
    let x = [1i];
    for mut loop_unused in x.iter() {}

    let mut normal_unused = 1i;
}

Compiling gives

<anon>:5:9: 5:26 warning: unused variable: `normal_unused`, #[warn(unused_variable)] on by default
<anon>:5     let mut normal_unused = 1i;
                 ^~~~~~~~~~~~~~~~~
<anon>:5:9: 5:26 warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
<anon>:5     let mut normal_unused = 1i;
                 ^~~~~~~~~~~~~~~~~

but loop_unused should get those sort of warnings too.

(This is possibly related to #16205 in that it's probably caused by a mishandling of the for pattern.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions