mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 17:53:56 +00:00
Fix various wrong uses of NestedVisitorMap::All
This commit is contained in:
parent
2026f29fdf
commit
29cb2f7eba
@ -67,7 +67,7 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
|
|||||||
walk_expr(self, expr);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||||
NestedVisitorMap::All(&self.cx.tcx.hir)
|
NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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> {
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||||
NestedVisitorMap::All(&self.cx.tcx.hir)
|
NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
|
|||||||
// don't continue over blocks, LateLintPass already does that
|
// don't continue over blocks, LateLintPass already does that
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||||
NestedVisitorMap::All(&self.cx.tcx.hir)
|
NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for DerefVisitor<'a, 'tcx> {
|
|||||||
hir::intravisit::walk_expr(self, expr);
|
hir::intravisit::walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
|
||||||
intravisit::NestedVisitorMap::All(&self.cx.tcx.hir)
|
intravisit::NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UsedVisitor<'a, 'tcx> {
|
|||||||
hir::intravisit::walk_expr(self, expr);
|
hir::intravisit::walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> hir::intravisit::NestedVisitorMap<'this, 'tcx> {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).sty {
|
||||||
ty::TyRef(_, ref tam) => {
|
ty::TyRef(_, ref tam) => {
|
||||||
match (&pat[0].node, &pat[1].node) {
|
match (&pat[0].node, &pat[1].node) {
|
||||||
(key, _) if pat_is_wild(cx, key, body) => (pat[1].span, "value", tam.ty, tam.mutbl),
|
(key, _) if pat_is_wild(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),
|
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", tam.ty, MutImmutable),
|
||||||
_ => return,
|
_ => 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 `'_'`.
|
/// 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 {
|
match *pat {
|
||||||
PatKind::Wild => true,
|
PatKind::Wild => true,
|
||||||
PatKind::Binding(_, _, ident, None) if ident.node.as_str().starts_with('_') => {
|
PatKind::Binding(_, _, ident, None) if ident.node.as_str().starts_with('_') => {
|
||||||
let mut visitor = UsedVisitor {
|
let mut visitor = UsedVisitor {
|
||||||
var: ident.node,
|
var: ident.node,
|
||||||
used: false,
|
used: false,
|
||||||
cx: cx,
|
|
||||||
};
|
};
|
||||||
walk_expr(&mut visitor, body);
|
walk_expr(&mut visitor, body);
|
||||||
!visitor.used
|
!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
|
var: ast::Name, // var to look for
|
||||||
used: bool, // has the var been used otherwise?
|
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) {
|
fn visit_expr(&mut self, expr: &'tcx Expr) {
|
||||||
if let ExprPath(QPath::Resolved(None, ref path)) = expr.node {
|
if let ExprPath(QPath::Resolved(None, ref path)) = expr.node {
|
||||||
if path.segments.len() == 1 && path.segments[0].name == self.var {
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||||
NestedVisitorMap::All(&self.cx.tcx.hir)
|
NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,6 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
|||||||
intravisit::walk_ty(self, ty);
|
intravisit::walk_ty(self, ty);
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> intravisit::NestedVisitorMap<'this, 'tcx> {
|
||||||
intravisit::NestedVisitorMap::All(&self.cx.tcx.hir)
|
intravisit::NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ fn lint_shadow<'a, 'tcx: 'a>(
|
|||||||
snippet(cx, pattern_span, "_"),
|
snippet(cx, pattern_span, "_"),
|
||||||
snippet(cx, expr.span, "..")),
|
snippet(cx, expr.span, "..")),
|
||||||
|db| { db.span_note(prev_span, "previous binding is here"); });
|
|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,
|
span_lint_and_then(cx,
|
||||||
SHADOW_REUSE,
|
SHADOW_REUSE,
|
||||||
pattern_span,
|
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()
|
!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,
|
name: Name,
|
||||||
result: bool,
|
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) {
|
fn visit_name(&mut self, _: Span, name: Name) {
|
||||||
if self.name == name {
|
if self.name == name {
|
||||||
self.result = true;
|
self.result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
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 {
|
let mut cs = ContainsSelf {
|
||||||
name: name,
|
name: name,
|
||||||
result: false,
|
result: false,
|
||||||
cx: cx,
|
|
||||||
};
|
};
|
||||||
cs.visit_expr(expr);
|
cs.visit_expr(expr);
|
||||||
cs.result
|
cs.result
|
||||||
|
@ -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) {
|
if in_macro(ty.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -701,7 +701,6 @@ impl<'a, 'tcx> TypeComplexityPass {
|
|||||||
let mut visitor = TypeComplexityVisitor {
|
let mut visitor = TypeComplexityVisitor {
|
||||||
score: 0,
|
score: 0,
|
||||||
nest: 1,
|
nest: 1,
|
||||||
cx: cx,
|
|
||||||
};
|
};
|
||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
visitor.score
|
visitor.score
|
||||||
@ -717,15 +716,14 @@ impl<'a, 'tcx> TypeComplexityPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Walks a type and assigns a complexity score to it.
|
/// Walks a type and assigns a complexity score to it.
|
||||||
struct TypeComplexityVisitor<'a, 'tcx: 'a> {
|
struct TypeComplexityVisitor{
|
||||||
/// total complexity score of the type
|
/// total complexity score of the type
|
||||||
score: u64,
|
score: u64,
|
||||||
/// current nesting level
|
/// current nesting level
|
||||||
nest: u64,
|
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) {
|
fn visit_ty(&mut self, ty: &'tcx Ty) {
|
||||||
let (add_score, sub_nest) = match ty.node {
|
let (add_score, sub_nest) = match ty.node {
|
||||||
// _, &x and *x have only small overhead; don't mess with nesting level
|
// _, &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;
|
self.nest -= sub_nest;
|
||||||
}
|
}
|
||||||
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
|
||||||
NestedVisitorMap::All(&self.cx.tcx.hir)
|
NestedVisitorMap::None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
tests/run-pass/regressions.rs
Normal file
8
tests/run-pass/regressions.rs
Normal 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
5
tests/ui/ices.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
// this used to ICE
|
||||||
|
fubar!();
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/ices.stderr
Normal file
8
tests/ui/ices.stderr
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user