Skip to content

Commit bc6465a

Browse files
committed
fix: don't lint in macro calls
1 parent 97213dc commit bc6465a

File tree

4 files changed

+5
-12
lines changed

4 files changed

+5
-12
lines changed

clippy_lints/src/mut_mut.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl<'tcx> intravisit::Visitor<'tcx> for MutVisitor<'_, 'tcx> {
7272
intravisit::walk_expr(self, body);
7373
} else if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, e) = expr.kind {
7474
if let hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Mut, _) = e.kind {
75+
if !expr.span.eq_ctxt(e.span) {
76+
return;
77+
}
7578
let mut applicability = Applicability::MaybeIncorrect;
7679
let sugg = Sugg::hir_with_applicability(self.cx, e, "..", &mut applicability);
7780
span_lint_hir_and_then(

tests/ui/mut_mut.fixed

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ fn main() {
4949
//~| mut_mut
5050
}
5151

52-
let mut z = inline!(&mut 3u32mut $(&mut 3u32));
53-
//~^ mut_mut
52+
let mut z = inline!(&mut $(&mut 3u32));
5453
}
5554

5655
fn issue939() {

tests/ui/mut_mut.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ fn main() {
5050
}
5151

5252
let mut z = inline!(&mut $(&mut 3u32));
53-
//~^ mut_mut
5453
}
5554

5655
fn issue939() {

tests/ui/mut_mut.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ error: an expression of form `&mut &mut _`
1313
LL | let mut x = &mut &mut 1u32;
1414
| ^^^^^^^^^^^^^^ help: remove the extra `&mut`: `&mut 1u32`
1515

16-
error: an expression of form `&mut &mut _`
17-
--> tests/ui/mut_mut.rs:52:25
18-
|
19-
LL | let mut z = inline!(&mut $(&mut 3u32));
20-
| ^ help: remove the extra `&mut`: `&mut 3u32`
21-
|
22-
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
23-
2416
error: this expression mutably borrows a mutable reference
2517
--> tests/ui/mut_mut.rs:35:21
2618
|
@@ -57,5 +49,5 @@ error: generally you want to avoid `&mut &mut _` if possible
5749
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
5850
| ^^^^^^^^^^^^^
5951

60-
error: aborting due to 9 previous errors
52+
error: aborting due to 8 previous errors
6153

0 commit comments

Comments
 (0)