rust
                                
                                 rust copied to clipboard
                                
                                    rust copied to clipboard
                            
                            
                            
                        "unused_mut" is not detected when variable type is mutable reference and the referent is mutated
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,
}
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
I think we should search systematically for all similar diagnostic holes/bugs regarding unnecessary muts. I filed two similar things for Clippy, but I think such mut diagnostics should be in rustc.
If this lint had existed, it would have helped me learn the rules around mut <ident> and &mut reborrowing faster.
This was fixed by https://github.com/rust-lang/rust/pull/110960 and the fix is included in Rust 1.71.0.