Skip to content

No warning given when mutability unnecessary in match arm pattern with mutable reference #54684

@dooblad

Description

@dooblad

The compiler doesn't notice and/or warn that a mutable reference in a match arm pattern doesn't need to be mutable.

I tried this code:

fn main() {
    let mut option = Some(Box::new(0));
    match option {
        Some(ref mut v) => println!("{}", v),
        None => (),
    };
}

I expected to see this happen: The compiler would give a warning, saying that mut is unnecessary in the first match arm.

Instead, this happened: The compiler gives no warnings.

Meta

rustc --version --verbose:

rustc 1.27.0 (3eda71b00 2018-06-19)
binary: rustc
commit-hash: 3eda71b00ad48d7bf4eef4c443e7f611fd061418
commit-date: 2018-06-19
host: x86_64-apple-darwin
release: 1.27.0
LLVM version: 6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions