mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 00:47:16 +00:00
Auto merge of #12442 - cookie-s:fix-mutmut-duplicate-diags, r=y21
[`mut_mut`]: Fix duplicate diags Relates to #12379 The `mut_mut` lint produced two diagnostics for each `mut mut` pattern in `ty` inside `block`s because `MutVisitor::visit_ty` was called from `MutMut::check_ty` and `MutMut::check_block` independently. This PR fixes the issue. --- changelog: [`mut_mut`]: Fix duplicate diagnostics
This commit is contained in:
commit
b2f9c4cbc7
3 changed files with 36 additions and 45 deletions
|
@ -35,9 +35,34 @@ impl<'tcx> LateLintPass<'tcx> for MutMut {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//@aux-build:proc_macros.rs
|
||||
//@compile-flags: -Zdeduplicate-diagnostics=yes
|
||||
|
||||
#![warn(clippy::mut_mut)]
|
||||
#![allow(unused)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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 {
|
||||
| ^^^^^^^^^^^^^
|
||||
|
@ -8,13 +8,13 @@ LL | fn fun(x: &mut &mut u32) -> bool {
|
|||
= help: to override `-D warnings` add `#[allow(clippy::mut_mut)]`
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
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));
|
||||
| ^
|
||||
|
@ -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)
|
||||
|
||||
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;
|
||||
| ^^^^^^
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
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;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue