]> git.lizzy.rs Git - rust.git/commitdiff
Fix various wrong uses of NestedVisitorMap::All
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 12 May 2017 10:02:42 +0000 (12:02 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 12 May 2017 10:02:42 +0000 (12:02 +0200)
12 files changed:
clippy_lints/src/block_in_if_condition.rs
clippy_lints/src/entry.rs
clippy_lints/src/eval_order_dependence.rs
clippy_lints/src/functions.rs
clippy_lints/src/let_if_seq.rs
clippy_lints/src/loops.rs
clippy_lints/src/mut_mut.rs
clippy_lints/src/shadow.rs
clippy_lints/src/types.rs
tests/run-pass/regressions.rs [new file with mode: 0644]
tests/ui/ices.rs [new file with mode: 0644]
tests/ui/ices.stderr [new file with mode: 0644]

index cabffa8e9697578e4954b336138f2826d896d39f..6c0523dc19809ea28e6efe0286635957fdba81d9 100644 (file)
@@ -67,7 +67,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
index 73d9f8ba16171d51a883dfed295a1bcedb768bb5..fd43b5bb6c61f54dcde92da9fb5c23f86191d5bf 100644 (file)
@@ -154,6 +154,6 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         }
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
index 2e8917598891d00b3ecf64184f86853aa63f204c..9f694dd1cff72b3046380022ea098e9ded11b1c4 100644 (file)
@@ -156,7 +156,7 @@ fn visit_block(&mut self, _: &'tcx Block) {
         // don't continue over blocks, LateLintPass already does that
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
@@ -341,7 +341,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
index 58d49c6fd238cf9966fc69a8578b2c1efa7b4d4e..0c4712a591172bbd6ae276abe2ebb13c79c71a6f 100644 (file)
@@ -200,7 +200,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
         hir::intravisit::walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
-        intravisit::NestedVisitorMap::All(&self.cx.tcx.hir)
+        intravisit::NestedVisitorMap::None
     }
 }
 
index 6fbe47c9e65f64e9fa62d667d98c65ea771b05ba..adda97bbc507d5f2a148a1f2e86393c386d7837f 100644 (file)
@@ -146,7 +146,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
         hir::intravisit::walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> hir::intravisit::NestedVisitorMap<'this, 'tcx> {
-        hir::intravisit::NestedVisitorMap::All(&self.cx.tcx.hir)
+        hir::intravisit::NestedVisitorMap::None
     }
 }
 
index 8c2712104bd09cea6af9a80c603df072213ccd68..c54a82984f19be2a2f976087b86a5277eb7e19eb 100644 (file)
@@ -799,8 +799,8 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
             let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).sty {
                 ty::TyRef(_, ref tam) => {
                     match (&pat[0].node, &pat[1].node) {
-                        (key, _) if pat_is_wild(cx, key, body) => (pat[1].span, "value", tam.ty, tam.mutbl),
-                        (_, value) if pat_is_wild(cx, value, body) => (pat[0].span, "key", tam.ty, MutImmutable),
+                        (key, _) if pat_is_wild(key, body) => (pat[1].span, "value", tam.ty, tam.mutbl),
+                        (_, value) if pat_is_wild(value, body) => (pat[0].span, "key", tam.ty, MutImmutable),
                         _ => return,
                     }
                 },
@@ -834,14 +834,13 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
 }
 
 /// Return true if the pattern is a `PatWild` or an ident prefixed with `'_'`.
-fn pat_is_wild<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, pat: &'tcx PatKind, body: &'tcx Expr) -> bool {
+fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool {
     match *pat {
         PatKind::Wild => true,
         PatKind::Binding(_, _, ident, None) if ident.node.as_str().starts_with('_') => {
             let mut visitor = UsedVisitor {
                 var: ident.node,
                 used: false,
-                cx: cx,
             };
             walk_expr(&mut visitor, body);
             !visitor.used
@@ -850,13 +849,12 @@ fn pat_is_wild<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, pat: &'tcx PatKind, bod
     }
 }
 
-struct UsedVisitor<'a, 'tcx: 'a> {
+struct UsedVisitor {
     var: ast::Name, // var to look for
     used: bool, // has the var been used otherwise?
-    cx: &'a LateContext<'a, 'tcx>,
 }
 
-impl<'a, 'tcx: 'a> Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
+impl<'tcx> Visitor<'tcx> for UsedVisitor {
     fn visit_expr(&mut self, expr: &'tcx Expr) {
         if let ExprPath(QPath::Resolved(None, ref path)) = expr.node {
             if path.segments.len() == 1 && path.segments[0].name == self.var {
@@ -868,7 +866,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
@@ -920,7 +918,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
@@ -962,7 +960,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
@@ -1105,7 +1103,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
@@ -1192,7 +1190,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
         walk_expr(self, expr);
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
index d5e4a0fdb26c93295e9610a537bae3428833b0c1..681bbc42a6f74177dbc6fc5b8c402aaf3da98478 100644 (file)
@@ -91,6 +91,6 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
         intravisit::walk_ty(self, ty);
     }
     fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
-        intravisit::NestedVisitorMap::All(&self.cx.tcx.hir)
+        intravisit::NestedVisitorMap::None
     }
 }
index 58eb4aafa2be8cc3c398265515cb2318185e9243..8a6b950327b931ed3835a032a4acbba83607804f 100644 (file)
@@ -251,7 +251,7 @@ fn lint_shadow<'a, 'tcx: 'a>(
                                         snippet(cx, pattern_span, "_"),
                                         snippet(cx, expr.span, "..")),
                                |db| { db.span_note(prev_span, "previous binding is here"); });
-        } else if contains_self(cx, name, expr) {
+        } else if contains_self(name, expr) {
             span_lint_and_then(cx,
                                SHADOW_REUSE,
                                pattern_span,
@@ -369,28 +369,26 @@ fn path_eq_name(name: Name, path: &Path) -> bool {
     !path.is_global() && path.segments.len() == 1 && path.segments[0].name.as_str() == name.as_str()
 }
 
-struct ContainsSelf<'a, 'tcx: 'a> {
+struct ContainsSelf {
     name: Name,
     result: bool,
-    cx: &'a LateContext<'a, 'tcx>,
 }
 
-impl<'a, 'tcx: 'a> Visitor<'tcx> for ContainsSelf<'a, 'tcx> {
+impl<'tcx> Visitor<'tcx> for ContainsSelf {
     fn visit_name(&mut self, _: Span, name: Name) {
         if self.name == name {
             self.result = true;
         }
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
-fn contains_self<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, name: Name, expr: &'tcx Expr) -> bool {
+fn contains_self(name: Name, expr: &Expr) -> bool {
     let mut cs = ContainsSelf {
         name: name,
         result: false,
-        cx: cx,
     };
     cs.visit_expr(expr);
     cs.result
index 0c9497752dbd54ce1720fa9b8ced4afc47e9fe12..7254862a38071f7adc8a440721d3664858b28a15 100644 (file)
@@ -693,7 +693,7 @@ fn check_fndecl(&self, cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl) {
         }
     }
 
-    fn check_type(&self, cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty) {
+    fn check_type(&self, cx: &LateContext, ty: &Ty) {
         if in_macro(ty.span) {
             return;
         }
@@ -701,7 +701,6 @@ fn check_type(&self, cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty) {
             let mut visitor = TypeComplexityVisitor {
                 score: 0,
                 nest: 1,
-                cx: cx,
             };
             visitor.visit_ty(ty);
             visitor.score
@@ -717,15 +716,14 @@ fn check_type(&self, cx: &LateContext<'a, 'tcx>, ty: &'tcx Ty) {
 }
 
 /// Walks a type and assigns a complexity score to it.
-struct TypeComplexityVisitor<'a, 'tcx: 'a> {
+struct TypeComplexityVisitor{
     /// total complexity score of the type
     score: u64,
     /// current nesting level
     nest: u64,
-    cx: &'a LateContext<'a, 'tcx>,
 }
 
-impl<'a, 'tcx: 'a> Visitor<'tcx> for TypeComplexityVisitor<'a, 'tcx> {
+impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
     fn visit_ty(&mut self, ty: &'tcx Ty) {
         let (add_score, sub_nest) = match ty.node {
             // _, &x and *x have only small overhead; don't mess with nesting level
@@ -757,7 +755,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty) {
         self.nest -= sub_nest;
     }
     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
-        NestedVisitorMap::All(&self.cx.tcx.hir)
+        NestedVisitorMap::None
     }
 }
 
diff --git a/tests/run-pass/regressions.rs b/tests/run-pass/regressions.rs
new file mode 100644 (file)
index 0000000..6e8b656
--- /dev/null
@@ -0,0 +1,8 @@
+#![feature(plugin)]
+#![plugin(clippy)]
+
+pub fn foo(bar: *const u8) {
+    println!("{:#p}", bar);
+}
+
+fn main() {}
diff --git a/tests/ui/ices.rs b/tests/ui/ices.rs
new file mode 100644 (file)
index 0000000..9c51296
--- /dev/null
@@ -0,0 +1,5 @@
+
+// this used to ICE
+fubar!();
+
+fn main() {}
diff --git a/tests/ui/ices.stderr b/tests/ui/ices.stderr
new file mode 100644 (file)
index 0000000..cadd7cd
--- /dev/null
@@ -0,0 +1,8 @@
+error: cannot find macro `fubar!` in this scope
+ --> $DIR/ices.rs:3:1
+  |
+3 | fubar!();
+  | ^^^^^
+
+error: aborting due to previous error
+