Skip to content

Incorrect unused_mut in let binding #132857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bartek358 opened this issue Nov 10, 2024 · 2 comments
Closed

Incorrect unused_mut in let binding #132857

bartek358 opened this issue Nov 10, 2024 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@bartek358
Copy link

Summary

When destructuring a &mut reference to a Copy type in a let binding, clippy considers using a mut binding to be needless if the variable is not mutated later. However, the binding with mut causes dereference and shortens the borrow, so its removal might lead to borrow checking errors.

Lint Name

unused_mut

Reproducer

playground

#[allow(unused_assignments, unused_variables, clippy::disallowed_names)]
fn main() {
    let mut foo = (1, 2);
    let (bar, mut baz) = &mut foo;
    *bar = 3;
    foo = (4, 5);
    println!("{baz}");
}

Version

rustc 1.84.0-nightly (59cec72a5 2024-11-08)
binary: rustc
commit-hash: 59cec72a57af178767a7b8e7f624b06cc50f1087
commit-date: 2024-11-08
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.3

Additional Labels

No response

@bartek358 bartek358 added the C-bug Category: This is a bug. label Nov 10, 2024
@y21
Copy link
Member

y21 commented Nov 10, 2024

unused_mut is a builtin rustc lint, so moving to the rustc issue tracker

@y21 y21 transferred this issue from rust-lang/rust-clippy Nov 10, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 10, 2024
@bartek358
Copy link
Author

Actually, now that you pointed that out I see it is a duplicate of #113451

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants