Skip to content

Commit 472e7ca

Browse files
committed
Deduplicate errors in mut_mut
1 parent f4c70d5 commit 472e7ca

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

clippy_lints/src/mut_mut.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc::hir;
21
use rustc::hir::intravisit;
2+
use rustc::hir;
33
use rustc::lint::*;
44
use rustc::ty::{TypeAndMut, TyRef};
55
use utils::{in_external_macro, recover_for_loop, span_lint};
@@ -28,14 +28,8 @@ impl LintPass for MutMut {
2828
}
2929

3030
impl LateLintPass for MutMut {
31-
fn check_block(&mut self, cx: &LateContext, block: &hir::Block) {
32-
intravisit::walk_block(&mut MutVisitor { cx: cx }, block);
33-
}
34-
35-
fn check_ty(&mut self, cx: &LateContext, ty: &hir::Ty) {
36-
use rustc::hir::intravisit::Visitor;
37-
38-
MutVisitor { cx: cx }.visit_ty(ty);
31+
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
32+
krate.visit_all_items(&mut MutVisitor { cx: cx });
3933
}
4034
}
4135

@@ -58,6 +52,7 @@ impl<'a, 'tcx, 'v> intravisit::Visitor<'v> for MutVisitor<'a, 'tcx> {
5852
// Let's ignore the generated code.
5953
intravisit::walk_expr(self, arg);
6054
intravisit::walk_expr(self, body);
55+
return;
6156
} else if let hir::ExprAddrOf(hir::MutMutable, ref e) = expr.node {
6257
if let hir::ExprAddrOf(hir::MutMutable, _) = e.node {
6358
span_lint(self.cx, MUT_MUT, expr.span, "generally you want to avoid `&mut &mut _` if possible");
@@ -68,6 +63,8 @@ impl<'a, 'tcx, 'v> intravisit::Visitor<'v> for MutVisitor<'a, 'tcx> {
6863
"this expression mutably borrows a mutable reference. Consider reborrowing");
6964
}
7065
}
66+
67+
intravisit::walk_expr(self, expr);
7168
}
7269

7370
fn visit_ty(&mut self, ty: &hir::Ty) {

tests/compile-fail/mut_mut.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ fn main() {
3131
let y : &mut &mut u32 = &mut &mut 2;
3232
//~^ ERROR generally you want to avoid `&mut &mut
3333
//~| ERROR generally you want to avoid `&mut &mut
34-
//~| ERROR generally you want to avoid `&mut &mut
3534
**y + **x;
3635
}
3736

@@ -41,8 +40,6 @@ fn main() {
4140
//~| ERROR generally you want to avoid `&mut &mut
4241
//~| ERROR generally you want to avoid `&mut &mut
4342
//~| ERROR generally you want to avoid `&mut &mut
44-
//~| ERROR generally you want to avoid `&mut &mut
45-
//~| ERROR generally you want to avoid `&mut &mut
4643
***y + **x;
4744
}
4845

0 commit comments

Comments
 (0)