-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
Reproducer should make it clear what the problem is
Lint Name
unnecessary_mut_passed
Reproducer
I tried this code:
macro_rules! x {
($f:ident) => {
$f(&mut 1);
}
}
fn f(x: &i32) {}
fn f2(x: &mut i32) {
*x += 1;
}
fn main() {
x!(f); // no `&mut` needed in expansion
x!(f2); // but in this expansion it is needed
}
I saw this happen:
warning: the function `f` doesn't need a mutable reference
--> src/main.rs:3:12
|
3 | $f(&mut 1);
| ^^^^^^
...
13 | x!(f);
| ----- in this macro invocation
If we remove the mutable reference and instead pass &1
, it won't compile because that fails in the second invocation x!(f2)
, which does require a mutable reference
I expected to see this happen: no warning.
Version
rustc 1.73.0-nightly (500647fd8 2023-07-27)
binary: rustc
commit-hash: 500647fd8138cc09e87edb08d62f81654fbf6ef8
commit-date: 2023-07-27
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have