-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
When the mutable reference passed is surrounded by parens -- for example to have a method called on -- the suggestion forgets to reinstate those parens. This can break the types, since the &
now might get seen as being placed on the entire expression.
Reproducer
I tried this code:
#![allow(unused, clippy::needless_borrow)]
#![warn(clippy::unnecessary_mut_passed)]
fn main() {
let _: usize = (&mut [0]).len();
}
I expected to see this happen:
warning: the method `len` doesn't need a mutable reference
--> src/lib.rs:5:20
|
5 | let _: usize = (&mut [0]).len();
| ^^^^^^^^^^ help: remove this `mut`: `(&[0])`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
Instead, this happened:
warning: the method `len` doesn't need a mutable reference
--> src/lib.rs:5:20
|
5 | let _: usize = (&mut [0]).len();
| ^^^^^^^^^^ help: remove this `mut`: `&[0]`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
Version
rustc 1.92.0-nightly (7c275d09e 2025-09-18)
binary: rustc
commit-hash: 7c275d09ea6b953d2cca169667184a7214bd14c7
commit-date: 2025-09-18
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1
Additional Labels
@rustbot label I-suggestion-causes-error
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied