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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue