[mut_mut]: Fix duplicate diags

This commit is contained in:
kcz 2024-03-08 21:50:45 -05:00
parent 0b4b684b46
commit 4e95b4a026
No known key found for this signature in database
GPG Key ID: 4D8C63ADDD1637A0
3 changed files with 36 additions and 45 deletions

View File

@ -35,9 +35,34 @@ impl<'tcx> LateLintPass<'tcx> for MutMut {
} }
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_>) { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx hir::Ty<'_>) {
use rustc_hir::intravisit::Visitor; if in_external_macro(cx.sess(), ty.span) {
return;
}
MutVisitor { cx }.visit_ty(ty); if let hir::TyKind::Ref(
_,
hir::MutTy {
ty: pty,
mutbl: hir::Mutability::Mut,
},
) = ty.kind
{
if let hir::TyKind::Ref(
_,
hir::MutTy {
mutbl: hir::Mutability::Mut,
..
},
) = pty.kind
{
span_lint(
cx,
MUT_MUT,
ty.span,
"generally you want to avoid `&mut &mut _` if possible",
);
}
}
} }
} }
@ -80,37 +105,4 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
} }
} }
} }
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
if in_external_macro(self.cx.sess(), ty.span) {
return;
}
if let hir::TyKind::Ref(
_,
hir::MutTy {
ty: pty,
mutbl: hir::Mutability::Mut,
},
) = ty.kind
{
if let hir::TyKind::Ref(
_,
hir::MutTy {
mutbl: hir::Mutability::Mut,
..
},
) = pty.kind
{
span_lint(
self.cx,
MUT_MUT,
ty.span,
"generally you want to avoid `&mut &mut _` if possible",
);
}
}
intravisit::walk_ty(self, ty);
}
} }

View File

@ -1,5 +1,4 @@
//@aux-build:proc_macros.rs //@aux-build:proc_macros.rs
//@compile-flags: -Zdeduplicate-diagnostics=yes
#![warn(clippy::mut_mut)] #![warn(clippy::mut_mut)]
#![allow(unused)] #![allow(unused)]

View File

@ -1,5 +1,5 @@
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:16:11 --> tests/ui/mut_mut.rs:15:11
| |
LL | fn fun(x: &mut &mut u32) -> bool { LL | fn fun(x: &mut &mut u32) -> bool {
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
@ -8,13 +8,13 @@ LL | fn fun(x: &mut &mut u32) -> bool {
= help: to override `-D warnings` add `#[allow(clippy::mut_mut)]` = help: to override `-D warnings` add `#[allow(clippy::mut_mut)]`
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:33:17 --> tests/ui/mut_mut.rs:32:17
| |
LL | let mut x = &mut &mut 1u32; LL | let mut x = &mut &mut 1u32;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:48:25 --> tests/ui/mut_mut.rs:47:25
| |
LL | let mut z = inline!(&mut $(&mut 3u32)); LL | let mut z = inline!(&mut $(&mut 3u32));
| ^ | ^
@ -22,37 +22,37 @@ LL | let mut z = inline!(&mut $(&mut 3u32));
= note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info)
error: this expression mutably borrows a mutable reference. Consider reborrowing error: this expression mutably borrows a mutable reference. Consider reborrowing
--> tests/ui/mut_mut.rs:35:21 --> tests/ui/mut_mut.rs:34:21
| |
LL | let mut y = &mut x; LL | let mut y = &mut x;
| ^^^^^^ | ^^^^^^
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:39:32 --> tests/ui/mut_mut.rs:38:32
| |
LL | let y: &mut &mut u32 = &mut &mut 2; LL | let y: &mut &mut u32 = &mut &mut 2;
| ^^^^^^^^^^^ | ^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:39:16 --> tests/ui/mut_mut.rs:38:16
| |
LL | let y: &mut &mut u32 = &mut &mut 2; LL | let y: &mut &mut u32 = &mut &mut 2;
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:44:37 --> tests/ui/mut_mut.rs:43:37
| |
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:44:16 --> tests/ui/mut_mut.rs:43:16
| |
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: generally you want to avoid `&mut &mut _` if possible error: generally you want to avoid `&mut &mut _` if possible
--> tests/ui/mut_mut.rs:44:21 --> tests/ui/mut_mut.rs:43:21
| |
LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2; LL | let y: &mut &mut &mut u32 = &mut &mut &mut 2;
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^