Fix various wrong uses of NestedVisitorMap::All

This commit is contained in:
Oliver Schneider 2017-05-12 12:02:42 +02:00
parent 2026f29fdf
commit 29cb2f7eba
12 changed files with 47 additions and 32 deletions

View File

@ -67,7 +67,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
walk_expr(self, expr);
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.hir)
NestedVisitorMap::None
}
}

View File

@ -154,6 +154,6 @@ impl<'a, 'tcx, 'b> Visitor<'tcx> for InsertVisitor<'a, 'tcx, 'b> {
}
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.hir)
NestedVisitorMap::None
}
}

View File

@ -156,7 +156,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
// 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 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
walk_expr(self, expr);
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.hir)
NestedVisitorMap::None
}
}

View File

@ -200,7 +200,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
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
}
}

View File

@ -146,7 +146,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
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
}
}

View 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 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
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 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
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 @@ impl<'a, 'tcx> Visitor<'tcx> for VarUsedAfterLoopVisitor<'a, 'tcx> {
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 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
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 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
walk_expr(self, expr);
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.hir)
NestedVisitorMap::None
}
}

View File

@ -91,6 +91,6 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
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
}
}

View 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

View File

@ -693,7 +693,7 @@ impl<'a, 'tcx> TypeComplexityPass {
}
}
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 @@ impl<'a, 'tcx> TypeComplexityPass {
let mut visitor = TypeComplexityVisitor {
score: 0,
nest: 1,
cx: cx,
};
visitor.visit_ty(ty);
visitor.score
@ -717,15 +716,14 @@ impl<'a, 'tcx> TypeComplexityPass {
}
/// 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 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for TypeComplexityVisitor<'a, 'tcx> {
self.nest -= sub_nest;
}
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::All(&self.cx.tcx.hir)
NestedVisitorMap::None
}
}

View File

@ -0,0 +1,8 @@
#![feature(plugin)]
#![plugin(clippy)]
pub fn foo(bar: *const u8) {
println!("{:#p}", bar);
}
fn main() {}

5
tests/ui/ices.rs Normal file
View File

@ -0,0 +1,5 @@
// this used to ICE
fubar!();
fn main() {}

8
tests/ui/ices.stderr Normal file
View File

@ -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