Skip to content

Commit dc1e8b0

Browse files
committed
[unnecessary_mut_passed]: don't lint in macro expansions
1 parent 2973096 commit dc1e8b0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

clippy_lints/src/mut_reference.rs

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ declare_lint_pass!(UnnecessaryMutPassed => [UNNECESSARY_MUT_PASSED]);
3737

3838
impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
3939
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
40+
if e.span.from_expansion() {
41+
// Issue #11268
42+
return;
43+
}
44+
4045
match e.kind {
4146
ExprKind::Call(fn_expr, arguments) => {
4247
if let ExprKind::Path(ref path) = fn_expr.kind {

tests/ui/mut_reference.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
#![allow(unused_variables)]
1+
#![allow(unused_variables, dead_code)]
22

33
fn takes_an_immutable_reference(a: &i32) {}
44
fn takes_a_mutable_reference(a: &mut i32) {}
55

6+
mod issue11268 {
7+
macro_rules! x {
8+
($f:expr) => {
9+
$f(&mut 1);
10+
};
11+
}
12+
13+
fn f() {
14+
x!(super::takes_an_immutable_reference);
15+
x!(super::takes_a_mutable_reference);
16+
}
17+
}
18+
619
struct MyStruct;
720

821
impl MyStruct {

tests/ui/mut_reference.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: the function `takes_an_immutable_reference` doesn't need a mutable reference
2-
--> $DIR/mut_reference.rs:17:34
2+
--> $DIR/mut_reference.rs:30:34
33
|
44
LL | takes_an_immutable_reference(&mut 42);
55
| ^^^^^^^
66
|
77
= note: `-D clippy::unnecessary-mut-passed` implied by `-D warnings`
88

99
error: the function `as_ptr` doesn't need a mutable reference
10-
--> $DIR/mut_reference.rs:19:12
10+
--> $DIR/mut_reference.rs:32:12
1111
|
1212
LL | as_ptr(&mut 42);
1313
| ^^^^^^^
1414

1515
error: the method `takes_an_immutable_reference` doesn't need a mutable reference
16-
--> $DIR/mut_reference.rs:23:44
16+
--> $DIR/mut_reference.rs:36:44
1717
|
1818
LL | my_struct.takes_an_immutable_reference(&mut 42);
1919
| ^^^^^^^
2020

2121
error: this argument is a mutable reference, but not used mutably
22-
--> $DIR/mut_reference.rs:11:44
22+
--> $DIR/mut_reference.rs:24:44
2323
|
2424
LL | fn takes_a_mutable_reference(&self, a: &mut i32) {}
2525
| ^^^^^^^^ help: consider changing to: `&i32`

0 commit comments

Comments
 (0)