Skip to content

Overly aggressive mut lint in match patterns #13866

Closed
@seanmonstar

Description

@seanmonstar
fn main() {
    match (3u, 'd') {
        (mut x, c@'a'..'z') |
        (mut x, c@'A'..'Z') |
        (mut x, c@'0'..'9') => {
            x = 4u;
            println!("c: {} {}", c, x);
        }
        _ => {
            println!("fail");
        }
    }
}

Output:

Untitled.rs:4:10: 4:15 warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
Untitled.rs:4         (mut x, c@'A'..'Z') |
                       ^~~~~
Untitled.rs:5:10: 5:15 warning: variable does not need to be mutable, #[warn(unused_mut)] on by default
Untitled.rs:5         (mut x, c@'0'..'9') => {
                       ^~~~~
c: d 4

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