Skip to content

unused_assignments does not care about unused assignments to reference derefs #44340

@oli-obk

Description

@oli-obk
pub fn foo(b: bool, x: &mut i32) {
    if b {
        *x = 6;
    }
    *x = 7;
}

does not emit the unused_assignments lint. I understand that this is not possible for DerefMut in general, because every call to deref_mut (via desugaring *) can result in a different reference, but for pure references everything should be good.

A case of not linting this causing a bug was found in rustc:

if idx < self.args.len() {
match self.args[idx] {
Operand::Consume(Lvalue::Local(l)) => *local = l,
ref op => bug!("Arg operand `{:?}` is {:?}, not local", idx, op)
}
}
*local = self.local_map[Local::new(idx - self.args.len())];

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.T-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