Is this a false positive of unused_mut

fn foo(x : &mut u8,y : &mut u8 ){
    *x += *y;
}

expect: unused_mut of y

You aren't using the mut capabilities of y, so no, it's valid.

3 Likes

I don't get a warning, are you asking about that? &u8 and &mut u8 are different types and the latter conveys exclusivity, not just mutability. Where as mut bindings (if you had a mut y ... or mut x) are basically a lint about overwriting or taking a &mut to binding accidentally, and removing the mut doesn't generally change any types.[1]

So changing the types of your parameters is a much different and further reaching change than removing a mut binding. I think unused_mut only cares about the binding situation.


  1. There are some exceptions related to binding modes, but at least some of those are bugs. ↩ī¸Ž

3 Likes