Skip to content

Unused variables inside for are not detected #17999

Closed
@huonw

Description

@huonw
fn main() {
    for _ in range(1i, 101) {
        let x = ();
        match () {
            a => {}
        }
    }
}

compiles without a peep, even though x and a are unused. Commenting out the for gives the expected output:

<anon>:3:13: 3:14 warning: unused variable: `x`, #[warn(unused_variable)] on by default
<anon>:3         let x = ();
                     ^
<anon>:5:13: 5:14 warning: unused variable: `a`, #[warn(unused_variable)] on by default
<anon>:5             a => {}
                     ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-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