Skip to content

"unused_mut" is not detected when variable type is mutable reference and the referent is mutated #88003

Open
@QuestionDriven

Description

@QuestionDriven

Code:

fn main() {
        let mut point = &mut Point { x: 10, y: 20};
        point.x = 30; 
        println!("{:?}", point);
}

#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

(Playground)

Current behavior:

no warning

Expected behavior:

warning: variable does not need to be mutable
 --> src/main.rs:2:13
  |
2 |         let mut point = &mut Point { x: 10, y: 20};
  |             ----^^^^^
  |             |
  |             help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-unused_mutLint: unused_mutT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions