Various straight-forward ports that override visit_nested_items
to do "in-situ" visits.
This commit is contained in:
parent
ac38021da1
commit
98b046e16e
@ -44,7 +44,7 @@ use syntax::parse::token::InternedString;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::util;
|
||||
use rustc_front::visit as hir_visit;
|
||||
use rustc_front::intravisit as hir_visit;
|
||||
use syntax::visit as ast_visit;
|
||||
use syntax::diagnostic;
|
||||
|
||||
@ -606,10 +606,12 @@ impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
|
||||
debug!("late context: enter_attrs({:?})", attrs);
|
||||
run_lints!(self, enter_lint_attrs, late_passes, attrs);
|
||||
}
|
||||
|
||||
fn exit_attrs(&mut self, attrs: &[ast::Attribute]) {
|
||||
debug!("late context: exit_attrs({:?})", attrs);
|
||||
run_lints!(self, exit_lint_attrs, late_passes, attrs);
|
||||
}
|
||||
}
|
||||
@ -633,15 +635,24 @@ impl<'a> LintContext for EarlyContext<'a> {
|
||||
}
|
||||
|
||||
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
|
||||
debug!("early context: exit_attrs({:?})", attrs);
|
||||
run_lints!(self, enter_lint_attrs, early_passes, attrs);
|
||||
}
|
||||
|
||||
fn exit_attrs(&mut self, attrs: &[ast::Attribute]) {
|
||||
debug!("early context: exit_attrs({:?})", attrs);
|
||||
run_lints!(self, exit_lint_attrs, early_passes, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
|
||||
/// Because lints are scoped lexically, we want to walk nested
|
||||
/// items in the context of the outer item, so enable
|
||||
/// deep-walking.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, it: &hir::Item) {
|
||||
self.with_lint_attrs(&it.attrs, |cx| {
|
||||
run_lints!(cx, check_item, late_passes, it);
|
||||
@ -947,6 +958,7 @@ impl<'a, 'tcx> IdVisitingOperation for LateContext<'a, 'tcx> {
|
||||
match self.sess().lints.borrow_mut().remove(&id) {
|
||||
None => {}
|
||||
Some(lints) => {
|
||||
debug!("LateContext::visit_id: id={:?} lints={:?}", id, lints);
|
||||
for (lint_id, span, msg) in lints {
|
||||
self.span_lint(lint_id.lint, span, &msg[..])
|
||||
}
|
||||
@ -1003,16 +1015,14 @@ impl LateLintPass for GatherNodeLevels {
|
||||
///
|
||||
/// Consumes the `lint_store` field of the `Session`.
|
||||
pub fn check_crate(tcx: &ty::ctxt,
|
||||
krate: &hir::Crate,
|
||||
exported_items: &ExportedItems) {
|
||||
|
||||
let krate = tcx.map.krate();
|
||||
let mut cx = LateContext::new(tcx, krate, exported_items);
|
||||
|
||||
// Visit the whole crate.
|
||||
cx.with_lint_attrs(&krate.attrs, |cx| {
|
||||
cx.visit_id(ast::CRATE_NODE_ID);
|
||||
cx.visit_ids(|v| {
|
||||
v.visited_outermost = true;
|
||||
hir_visit::walk_crate(v, krate);
|
||||
});
|
||||
|
||||
|
@ -34,7 +34,7 @@ pub use self::LintSource::*;
|
||||
use std::hash;
|
||||
use std::ascii::AsciiExt;
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::visit::FnKind;
|
||||
use rustc_front::intravisit::FnKind;
|
||||
use syntax::visit as ast_visit;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
@ -218,7 +218,7 @@ pub type EarlyLintPassObject = Box<EarlyLintPass + 'static>;
|
||||
pub type LateLintPassObject = Box<LateLintPass + 'static>;
|
||||
|
||||
/// Identifies a lint known to the compiler.
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct LintId {
|
||||
// Identity is based on pointer equality of this field.
|
||||
lint: &'static Lint,
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
use front::map as ast_map;
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
use rustc_front::intravisit::{self, Visitor};
|
||||
|
||||
use middle::{def, pat_util, privacy, ty};
|
||||
use middle::def_id::{DefId};
|
||||
@ -182,29 +182,29 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
||||
.contains(&attr::ReprExtern)
|
||||
});
|
||||
|
||||
visit::walk_item(self, &*item);
|
||||
intravisit::walk_item(self, &*item);
|
||||
}
|
||||
hir::ItemEnum(..) => {
|
||||
self.inherited_pub_visibility = item.vis == hir::Public;
|
||||
visit::walk_item(self, &*item);
|
||||
intravisit::walk_item(self, &*item);
|
||||
}
|
||||
hir::ItemFn(..)
|
||||
| hir::ItemTy(..)
|
||||
| hir::ItemStatic(..)
|
||||
| hir::ItemConst(..) => {
|
||||
visit::walk_item(self, &*item);
|
||||
intravisit::walk_item(self, &*item);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
ast_map::NodeTraitItem(trait_item) => {
|
||||
visit::walk_trait_item(self, trait_item);
|
||||
intravisit::walk_trait_item(self, trait_item);
|
||||
}
|
||||
ast_map::NodeImplItem(impl_item) => {
|
||||
visit::walk_impl_item(self, impl_item);
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
ast_map::NodeForeignItem(foreign_item) => {
|
||||
visit::walk_foreign_item(self, &*foreign_item);
|
||||
intravisit::walk_foreign_item(self, &*foreign_item);
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
@ -227,7 +227,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
});
|
||||
self.live_symbols.extend(live_fields.map(|f| f.node.id));
|
||||
|
||||
visit::walk_struct_def(self, def);
|
||||
intravisit::walk_struct_def(self, def);
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &hir::Expr) {
|
||||
@ -244,7 +244,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
_ => ()
|
||||
}
|
||||
|
||||
visit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, arm: &hir::Arm) {
|
||||
@ -257,10 +257,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
// can't be reached unless the variant is constructed elsewhere.
|
||||
let len = self.ignore_variant_stack.len();
|
||||
self.ignore_variant_stack.push_all(&*variants);
|
||||
visit::walk_arm(self, arm);
|
||||
intravisit::walk_arm(self, arm);
|
||||
self.ignore_variant_stack.truncate(len);
|
||||
} else {
|
||||
visit::walk_arm(self, arm);
|
||||
intravisit::walk_arm(self, arm);
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,23 +278,18 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
self.ignore_non_const_paths = true;
|
||||
visit::walk_pat(self, pat);
|
||||
intravisit::walk_pat(self, pat);
|
||||
self.ignore_non_const_paths = false;
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
|
||||
self.lookup_and_handle_definition(&id);
|
||||
visit::walk_path(self, path);
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
|
||||
fn visit_path_list_item(&mut self, path: &hir::Path, item: &hir::PathListItem) {
|
||||
self.lookup_and_handle_definition(&item.node.id());
|
||||
visit::walk_path_list_item(self, path, item);
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, _: &hir::Item) {
|
||||
// Do not recurse into items. These items will be added to the
|
||||
// worklist and recursed into manually if necessary.
|
||||
intravisit::walk_path_list_item(self, path, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,7 +366,6 @@ impl<'v> Visitor<'v> for LifeSeeder {
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
visit::walk_item(self, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -408,7 +402,7 @@ fn create_and_seed_worklist(tcx: &ty::ctxt,
|
||||
let mut life_seeder = LifeSeeder {
|
||||
worklist: worklist
|
||||
};
|
||||
visit::walk_crate(&mut life_seeder, krate);
|
||||
krate.visit_all_items(&mut life_seeder);
|
||||
|
||||
return life_seeder.worklist;
|
||||
}
|
||||
@ -530,6 +524,14 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
/// Walk nested items in place so that we don't report dead-code
|
||||
/// on inner functions when the outer function is already getting
|
||||
/// an error. We could do this also by checking the parents, but
|
||||
/// this is how the code is setup and it seems harmless enough.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
if self.should_warn_about_item(item) {
|
||||
self.warn_dead_code(
|
||||
@ -540,7 +542,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
);
|
||||
} else {
|
||||
// Only continue if we didn't warn
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -549,7 +551,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
self.warn_dead_code(variant.node.data.id(), variant.span,
|
||||
variant.node.name, "variant");
|
||||
} else {
|
||||
visit::walk_variant(self, variant, g, id);
|
||||
intravisit::walk_variant(self, variant, g, id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -557,7 +559,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
if !self.symbol_is_live(fi.id, None) {
|
||||
self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant());
|
||||
}
|
||||
visit::walk_foreign_item(self, fi);
|
||||
intravisit::walk_foreign_item(self, fi);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, field: &hir::StructField) {
|
||||
@ -566,7 +568,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
field.node.name().unwrap(), "struct field");
|
||||
}
|
||||
|
||||
visit::walk_struct_field(self, field);
|
||||
intravisit::walk_struct_field(self, field);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
|
||||
@ -576,14 +578,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
self.warn_dead_code(impl_item.id, impl_item.span,
|
||||
impl_item.name, "associated const");
|
||||
}
|
||||
visit::walk_expr(self, expr)
|
||||
intravisit::walk_expr(self, expr)
|
||||
}
|
||||
hir::ImplItemKind::Method(_, ref body) => {
|
||||
if !self.symbol_is_live(impl_item.id, None) {
|
||||
self.warn_dead_code(impl_item.id, impl_item.span,
|
||||
impl_item.name, "method");
|
||||
}
|
||||
visit::walk_block(self, body)
|
||||
intravisit::walk_block(self, body)
|
||||
}
|
||||
hir::ImplItemKind::Type(..) => {}
|
||||
}
|
||||
@ -593,10 +595,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) {
|
||||
match trait_item.node {
|
||||
hir::ConstTraitItem(_, Some(ref expr)) => {
|
||||
visit::walk_expr(self, expr)
|
||||
intravisit::walk_expr(self, expr)
|
||||
}
|
||||
hir::MethodTraitItem(_, Some(ref body)) => {
|
||||
visit::walk_block(self, body)
|
||||
intravisit::walk_block(self, body)
|
||||
}
|
||||
hir::ConstTraitItem(_, None) |
|
||||
hir::MethodTraitItem(_, None) |
|
||||
@ -612,5 +614,5 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
let live_symbols = find_live(tcx, exported_items,
|
||||
reachable_symbols, krate);
|
||||
let mut visitor = DeadVisitor { tcx: tcx, live_symbols: live_symbols };
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ use util::nodemap::{DefIdMap, FnvHashSet, FnvHashMap};
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{Block, Crate, Item, Generics, StructField, Variant};
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
use rustc_front::intravisit::{self, Visitor};
|
||||
|
||||
use std::mem::replace;
|
||||
use std::cmp::Ordering;
|
||||
@ -174,6 +174,13 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
/// Because stability levels are scoped lexically, we want to walk
|
||||
/// nested items in the context of the outer item, so enable
|
||||
/// deep-walking.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, i: &Item) {
|
||||
let orig_in_trait_impl = self.in_trait_impl;
|
||||
let orig_in_enum = self.in_enum;
|
||||
@ -203,7 +210,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
self.annotate(i.id, &i.attrs, i.span, kind, |v| {
|
||||
visit::walk_item(v, i)
|
||||
intravisit::walk_item(v, i)
|
||||
});
|
||||
self.in_trait_impl = orig_in_trait_impl;
|
||||
self.in_enum = orig_in_enum;
|
||||
@ -211,7 +218,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &hir::TraitItem) {
|
||||
self.annotate(ti.id, &ti.attrs, ti.span, AnnotationKind::Required, |v| {
|
||||
visit::walk_trait_item(v, ti);
|
||||
intravisit::walk_trait_item(v, ti);
|
||||
});
|
||||
}
|
||||
|
||||
@ -222,13 +229,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
AnnotationKind::Required
|
||||
};
|
||||
self.annotate(ii.id, &ii.attrs, ii.span, kind, |v| {
|
||||
visit::walk_impl_item(v, ii);
|
||||
intravisit::walk_impl_item(v, ii);
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, var: &Variant, g: &'v Generics, item_id: NodeId) {
|
||||
self.annotate(var.node.data.id(), &var.node.attrs, var.span, AnnotationKind::Required, |v| {
|
||||
visit::walk_variant(v, var, g, item_id);
|
||||
intravisit::walk_variant(v, var, g, item_id);
|
||||
})
|
||||
}
|
||||
|
||||
@ -240,13 +247,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
AnnotationKind::Required
|
||||
};
|
||||
self.annotate(s.node.id, &s.node.attrs, s.span, kind, |v| {
|
||||
visit::walk_struct_field(v, s);
|
||||
intravisit::walk_struct_field(v, s);
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
|
||||
self.annotate(i.id, &i.attrs, i.span, AnnotationKind::Required, |v| {
|
||||
visit::walk_foreign_item(v, i);
|
||||
intravisit::walk_foreign_item(v, i);
|
||||
});
|
||||
}
|
||||
|
||||
@ -259,7 +266,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
|
||||
impl<'tcx> Index<'tcx> {
|
||||
/// Construct the stability index for a crate being compiled.
|
||||
pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, krate: &Crate, export_map: &PublicItems) {
|
||||
pub fn build(&mut self, tcx: &ty::ctxt<'tcx>, krate: &'tcx Crate, export_map: &PublicItems) {
|
||||
let mut annotator = Annotator {
|
||||
tcx: tcx,
|
||||
index: self,
|
||||
@ -269,7 +276,7 @@ impl<'tcx> Index<'tcx> {
|
||||
in_enum: false,
|
||||
};
|
||||
annotator.annotate(ast::CRATE_NODE_ID, &krate.attrs, krate.span, AnnotationKind::Required,
|
||||
|v| visit::walk_crate(v, krate));
|
||||
|v| intravisit::walk_crate(v, krate));
|
||||
}
|
||||
|
||||
pub fn new(krate: &Crate) -> Index {
|
||||
@ -308,9 +315,7 @@ pub fn check_unstable_api_usage(tcx: &ty::ctxt)
|
||||
used_features: FnvHashMap(),
|
||||
in_skip_block: 0,
|
||||
};
|
||||
|
||||
let krate = tcx.map.krate();
|
||||
visit::walk_crate(&mut checker, krate);
|
||||
intravisit::walk_crate(&mut checker, tcx.map.krate());
|
||||
|
||||
let used_features = checker.used_features;
|
||||
return used_features;
|
||||
@ -379,6 +384,13 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
|
||||
/// Because stability levels are scoped lexically, we want to walk
|
||||
/// nested items in the context of the outer item, so enable
|
||||
/// deep-walking.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
// When compiling with --test we don't enforce stability on the
|
||||
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
|
||||
@ -387,31 +399,31 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
|
||||
|
||||
check_item(self.tcx, item, true,
|
||||
&mut |id, sp, stab| self.check(id, sp, stab));
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, ex: &hir::Expr) {
|
||||
check_expr(self.tcx, ex,
|
||||
&mut |id, sp, stab| self.check(id, sp, stab));
|
||||
visit::walk_expr(self, ex);
|
||||
intravisit::walk_expr(self, ex);
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
|
||||
check_path(self.tcx, path, id,
|
||||
&mut |id, sp, stab| self.check(id, sp, stab));
|
||||
visit::walk_path(self, path)
|
||||
intravisit::walk_path(self, path)
|
||||
}
|
||||
|
||||
fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) {
|
||||
check_path_list_item(self.tcx, item,
|
||||
&mut |id, sp, stab| self.check(id, sp, stab));
|
||||
visit::walk_path_list_item(self, prefix, item)
|
||||
intravisit::walk_path_list_item(self, prefix, item)
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pat: &hir::Pat) {
|
||||
check_pat(self.tcx, pat,
|
||||
&mut |id, sp, stab| self.check(id, sp, stab));
|
||||
visit::walk_pat(self, pat)
|
||||
intravisit::walk_pat(self, pat)
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, b: &hir::Block) {
|
||||
@ -425,7 +437,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_block(self, b);
|
||||
intravisit::walk_block(self, b);
|
||||
self.in_skip_block = old_skip_count;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,7 @@
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, SipHasher, Hasher};
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::intravisit as visit;
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct Svh {
|
||||
@ -83,7 +83,7 @@ impl Svh {
|
||||
}
|
||||
|
||||
{
|
||||
let mut visit = svh_visitor::make(&mut state);
|
||||
let mut visit = svh_visitor::make(&mut state, krate);
|
||||
visit::walk_crate(&mut visit, krate);
|
||||
}
|
||||
|
||||
@ -134,19 +134,20 @@ mod svh_visitor {
|
||||
use syntax::ast::{self, Name, NodeId};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use rustc_front::visit;
|
||||
use rustc_front::visit::{Visitor, FnKind};
|
||||
use rustc_front::intravisit as visit;
|
||||
use rustc_front::intravisit::{Visitor, FnKind};
|
||||
use rustc_front::hir::*;
|
||||
use rustc_front::hir;
|
||||
|
||||
use std::hash::{Hash, SipHasher};
|
||||
|
||||
pub struct StrictVersionHashVisitor<'a> {
|
||||
pub krate: &'a Crate,
|
||||
pub st: &'a mut SipHasher,
|
||||
}
|
||||
|
||||
pub fn make<'a>(st: &'a mut SipHasher) -> StrictVersionHashVisitor<'a> {
|
||||
StrictVersionHashVisitor { st: st }
|
||||
pub fn make<'a>(st: &'a mut SipHasher, krate: &'a Crate) -> StrictVersionHashVisitor<'a> {
|
||||
StrictVersionHashVisitor { st: st, krate: krate }
|
||||
}
|
||||
|
||||
// To off-load the bulk of the hash-computation on #[derive(Hash)],
|
||||
@ -300,15 +301,19 @@ mod svh_visitor {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> {
|
||||
fn visit_variant_data(&mut self, s: &VariantData, name: Name,
|
||||
g: &Generics, _: NodeId, _: Span) {
|
||||
impl<'a> Visitor<'a> for StrictVersionHashVisitor<'a> {
|
||||
fn visit_nested_item(&mut self, item: ItemId) {
|
||||
self.visit_item(self.krate.item(item.id))
|
||||
}
|
||||
|
||||
fn visit_variant_data(&mut self, s: &'a VariantData, name: Name,
|
||||
g: &'a Generics, _: NodeId, _: Span) {
|
||||
SawStructDef(name.as_str()).hash(self.st);
|
||||
visit::walk_generics(self, g);
|
||||
visit::walk_struct_def(self, s)
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) {
|
||||
fn visit_variant(&mut self, v: &'a Variant, g: &'a Generics, item_id: NodeId) {
|
||||
SawVariant.hash(self.st);
|
||||
// walk_variant does not call walk_generics, so do it here.
|
||||
visit::walk_generics(self, g);
|
||||
@ -333,11 +338,11 @@ mod svh_visitor {
|
||||
SawIdent(name.as_str()).hash(self.st);
|
||||
}
|
||||
|
||||
fn visit_lifetime(&mut self, l: &Lifetime) {
|
||||
fn visit_lifetime(&mut self, l: &'a Lifetime) {
|
||||
SawLifetime(l.name.as_str()).hash(self.st);
|
||||
}
|
||||
|
||||
fn visit_lifetime_def(&mut self, l: &LifetimeDef) {
|
||||
fn visit_lifetime_def(&mut self, l: &'a LifetimeDef) {
|
||||
SawLifetimeDef(l.lifetime.name.as_str()).hash(self.st);
|
||||
}
|
||||
|
||||
@ -346,15 +351,15 @@ mod svh_visitor {
|
||||
// monomorphization and cross-crate inlining generally implies
|
||||
// that a change to a crate body will require downstream
|
||||
// crates to be recompiled.
|
||||
fn visit_expr(&mut self, ex: &Expr) {
|
||||
fn visit_expr(&mut self, ex: &'a Expr) {
|
||||
SawExpr(saw_expr(&ex.node)).hash(self.st); visit::walk_expr(self, ex)
|
||||
}
|
||||
|
||||
fn visit_stmt(&mut self, s: &Stmt) {
|
||||
fn visit_stmt(&mut self, s: &'a Stmt) {
|
||||
SawStmt(saw_stmt(&s.node)).hash(self.st); visit::walk_stmt(self, s)
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, i: &ForeignItem) {
|
||||
fn visit_foreign_item(&mut self, i: &'a ForeignItem) {
|
||||
// FIXME (#14132) ideally we would incorporate privacy (or
|
||||
// perhaps reachability) somewhere here, so foreign items
|
||||
// that do not leak into downstream crates would not be
|
||||
@ -362,7 +367,7 @@ mod svh_visitor {
|
||||
SawForeignItem.hash(self.st); visit::walk_foreign_item(self, i)
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, i: &Item) {
|
||||
fn visit_item(&mut self, i: &'a Item) {
|
||||
// FIXME (#14132) ideally would incorporate reachability
|
||||
// analysis somewhere here, so items that never leak into
|
||||
// downstream crates (e.g. via monomorphisation or
|
||||
@ -370,64 +375,64 @@ mod svh_visitor {
|
||||
SawItem.hash(self.st); visit::walk_item(self, i)
|
||||
}
|
||||
|
||||
fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId) {
|
||||
fn visit_mod(&mut self, m: &'a Mod, _s: Span, _n: NodeId) {
|
||||
SawMod.hash(self.st); visit::walk_mod(self, m)
|
||||
}
|
||||
|
||||
fn visit_decl(&mut self, d: &Decl) {
|
||||
fn visit_decl(&mut self, d: &'a Decl) {
|
||||
SawDecl.hash(self.st); visit::walk_decl(self, d)
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, t: &Ty) {
|
||||
fn visit_ty(&mut self, t: &'a Ty) {
|
||||
SawTy.hash(self.st); visit::walk_ty(self, t)
|
||||
}
|
||||
|
||||
fn visit_generics(&mut self, g: &Generics) {
|
||||
fn visit_generics(&mut self, g: &'a Generics) {
|
||||
SawGenerics.hash(self.st); visit::walk_generics(self, g)
|
||||
}
|
||||
|
||||
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl,
|
||||
b: &'v Block, s: Span, _: NodeId) {
|
||||
fn visit_fn(&mut self, fk: FnKind<'a>, fd: &'a FnDecl,
|
||||
b: &'a Block, s: Span, _: NodeId) {
|
||||
SawFn.hash(self.st); visit::walk_fn(self, fk, fd, b, s)
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, ti: &TraitItem) {
|
||||
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
|
||||
SawTraitItem.hash(self.st); visit::walk_trait_item(self, ti)
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &ImplItem) {
|
||||
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
|
||||
SawImplItem.hash(self.st); visit::walk_impl_item(self, ii)
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &StructField) {
|
||||
fn visit_struct_field(&mut self, s: &'a StructField) {
|
||||
SawStructField.hash(self.st); visit::walk_struct_field(self, s)
|
||||
}
|
||||
|
||||
fn visit_explicit_self(&mut self, es: &ExplicitSelf) {
|
||||
fn visit_explicit_self(&mut self, es: &'a ExplicitSelf) {
|
||||
SawExplicitSelf.hash(self.st); visit::walk_explicit_self(self, es)
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &Path, _: ast::NodeId) {
|
||||
fn visit_path(&mut self, path: &'a Path, _: ast::NodeId) {
|
||||
SawPath.hash(self.st); visit::walk_path(self, path)
|
||||
}
|
||||
|
||||
fn visit_path_list_item(&mut self, prefix: &Path, item: &'v PathListItem) {
|
||||
fn visit_path_list_item(&mut self, prefix: &'a Path, item: &'a PathListItem) {
|
||||
SawPath.hash(self.st); visit::walk_path_list_item(self, prefix, item)
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, b: &Block) {
|
||||
fn visit_block(&mut self, b: &'a Block) {
|
||||
SawBlock.hash(self.st); visit::walk_block(self, b)
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, p: &Pat) {
|
||||
fn visit_pat(&mut self, p: &'a Pat) {
|
||||
SawPat.hash(self.st); visit::walk_pat(self, p)
|
||||
}
|
||||
|
||||
fn visit_local(&mut self, l: &Local) {
|
||||
fn visit_local(&mut self, l: &'a Local) {
|
||||
SawLocal.hash(self.st); visit::walk_local(self, l)
|
||||
}
|
||||
|
||||
fn visit_arm(&mut self, a: &Arm) {
|
||||
fn visit_arm(&mut self, a: &'a Arm) {
|
||||
SawArm.hash(self.st); visit::walk_arm(self, a)
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ use self::FieldName::*;
|
||||
use std::mem::replace;
|
||||
|
||||
use rustc_front::hir;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
use rustc_front::intravisit::{self, Visitor};
|
||||
|
||||
use rustc::middle::def;
|
||||
use rustc::middle::def_id::DefId;
|
||||
@ -63,12 +63,18 @@ type CheckResult = Option<(Span, String, Option<(Span, String)>)>;
|
||||
/// The parent visitor, used to determine what's the parent of what (node-wise)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct ParentVisitor {
|
||||
struct ParentVisitor<'a, 'tcx:'a> {
|
||||
tcx: &'a ty::ctxt<'tcx>,
|
||||
parents: NodeMap<ast::NodeId>,
|
||||
curparent: ast::NodeId,
|
||||
}
|
||||
|
||||
impl<'v> Visitor<'v> for ParentVisitor {
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for ParentVisitor<'a, 'tcx> {
|
||||
/// We want to visit items in the context of their containing
|
||||
/// module and so forth, so supply a crate for doing a deep walk.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
self.parents.insert(item.id, self.curparent);
|
||||
|
||||
@ -99,16 +105,16 @@ impl<'v> Visitor<'v> for ParentVisitor {
|
||||
|
||||
_ => {}
|
||||
}
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
self.curparent = prev;
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, a: &hir::ForeignItem) {
|
||||
self.parents.insert(a.id, self.curparent);
|
||||
visit::walk_foreign_item(self, a);
|
||||
intravisit::walk_foreign_item(self, a);
|
||||
}
|
||||
|
||||
fn visit_fn(&mut self, a: visit::FnKind<'v>, b: &'v hir::FnDecl,
|
||||
fn visit_fn(&mut self, a: intravisit::FnKind<'v>, b: &'v hir::FnDecl,
|
||||
c: &'v hir::Block, d: Span, id: ast::NodeId) {
|
||||
// We already took care of some trait methods above, otherwise things
|
||||
// like impl methods and pub trait methods are parented to the
|
||||
@ -116,7 +122,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
|
||||
if !self.parents.contains_key(&id) {
|
||||
self.parents.insert(id, self.curparent);
|
||||
}
|
||||
visit::walk_fn(self, a, b, c, d);
|
||||
intravisit::walk_fn(self, a, b, c, d);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) {
|
||||
@ -125,7 +131,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
|
||||
if !self.parents.contains_key(&ii.id) {
|
||||
self.parents.insert(ii.id, self.curparent);
|
||||
}
|
||||
visit::walk_impl_item(self, ii);
|
||||
intravisit::walk_impl_item(self, ii);
|
||||
}
|
||||
|
||||
fn visit_variant_data(&mut self, s: &hir::VariantData, _: ast::Name,
|
||||
@ -141,7 +147,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
|
||||
for field in s.fields() {
|
||||
self.parents.insert(field.node.id, self.curparent);
|
||||
}
|
||||
visit::walk_struct_def(self, s)
|
||||
intravisit::walk_struct_def(self, s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,6 +222,11 @@ impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
/// We want to visit items in the context of their containing
|
||||
/// module and so forth, so supply a crate for doing a deep walk.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
let orig_all_public = self.prev_public;
|
||||
let orig_all_exported = self.prev_exported;
|
||||
@ -362,7 +373,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
|
||||
self.prev_public = orig_all_public;
|
||||
self.prev_exported = orig_all_exported;
|
||||
@ -375,7 +386,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
// Blocks can have exported and public items, for example impls, but they always
|
||||
// start as non-public and non-exported regardless of publicity of a function,
|
||||
// constant, type, field, etc. in which this block resides
|
||||
visit::walk_block(self, b);
|
||||
intravisit::walk_block(self, b);
|
||||
|
||||
self.prev_public = orig_all_public;
|
||||
self.prev_exported = orig_all_exported;
|
||||
@ -392,7 +403,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
visit::walk_mod(self, m)
|
||||
intravisit::walk_mod(self, m)
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, md: &'v hir::MacroDef) {
|
||||
@ -895,9 +906,15 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
||||
/// We want to visit items in the context of their containing
|
||||
/// module and so forth, so supply a crate for doing a deep walk.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
let orig_curitem = replace(&mut self.curitem, item.id);
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
self.curitem = orig_curitem;
|
||||
}
|
||||
|
||||
@ -958,7 +975,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
visit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn visit_pat(&mut self, pattern: &hir::Pat) {
|
||||
@ -1004,19 +1021,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
visit::walk_pat(self, pattern);
|
||||
intravisit::walk_pat(self, pattern);
|
||||
}
|
||||
|
||||
fn visit_foreign_item(&mut self, fi: &hir::ForeignItem) {
|
||||
self.in_foreign = true;
|
||||
visit::walk_foreign_item(self, fi);
|
||||
intravisit::walk_foreign_item(self, fi);
|
||||
self.in_foreign = false;
|
||||
}
|
||||
|
||||
fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) {
|
||||
if !path.segments.is_empty() {
|
||||
self.check_path(path.span, id, path.segments.last().unwrap().identifier.name);
|
||||
visit::walk_path(self, path);
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1029,7 +1046,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
|
||||
self.tcx.sess.bug("`self` import in an import list with empty prefix");
|
||||
};
|
||||
self.check_path(item.span, item.node.id(), name);
|
||||
visit::walk_path_list_item(self, prefix, item);
|
||||
intravisit::walk_path_list_item(self, prefix, item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1043,6 +1060,12 @@ struct SanePrivacyVisitor<'a, 'tcx: 'a> {
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for SanePrivacyVisitor<'a, 'tcx> {
|
||||
/// We want to visit items in the context of their containing
|
||||
/// module and so forth, so supply a crate for doing a deep walk.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
self.check_sane_privacy(item);
|
||||
if self.in_block {
|
||||
@ -1054,13 +1077,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for SanePrivacyVisitor<'a, 'tcx> {
|
||||
// Modules turn privacy back on, otherwise we inherit
|
||||
self.in_block = if let hir::ItemMod(..) = item.node { false } else { orig_in_block };
|
||||
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
self.in_block = orig_in_block;
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, b: &'v hir::Block) {
|
||||
let orig_in_block = replace(&mut self.in_block, true);
|
||||
visit::walk_block(self, b);
|
||||
intravisit::walk_block(self, b);
|
||||
self.in_block = orig_in_block;
|
||||
}
|
||||
}
|
||||
@ -1220,7 +1243,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for CheckTypeForPrivatenessVisitor<'a, 'b, 't
|
||||
}
|
||||
}
|
||||
self.at_outer_type = false;
|
||||
visit::walk_ty(self, ty)
|
||||
intravisit::walk_ty(self, ty)
|
||||
}
|
||||
|
||||
// don't want to recurse into [, .. expr]
|
||||
@ -1228,6 +1251,12 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for CheckTypeForPrivatenessVisitor<'a, 'b, 't
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
/// We want to visit items in the context of their containing
|
||||
/// module and so forth, so supply a crate for doing a deep walk.
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.tcx.map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &hir::Item) {
|
||||
match item.node {
|
||||
// contents of a private mod can be reexported, so we need
|
||||
@ -1313,7 +1342,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
not_private_trait &&
|
||||
trait_or_some_public_method {
|
||||
|
||||
visit::walk_generics(self, g);
|
||||
intravisit::walk_generics(self, g);
|
||||
|
||||
match *trait_ref {
|
||||
None => {
|
||||
@ -1328,10 +1357,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
hir::ImplItemKind::Method(..)
|
||||
if self.item_is_public(&impl_item.id, impl_item.vis) =>
|
||||
{
|
||||
visit::walk_impl_item(self, impl_item)
|
||||
intravisit::walk_impl_item(self, impl_item)
|
||||
}
|
||||
hir::ImplItemKind::Type(..) => {
|
||||
visit::walk_impl_item(self, impl_item)
|
||||
intravisit::walk_impl_item(self, impl_item)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -1351,7 +1380,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
//
|
||||
// Those in 2. are warned via walk_generics and this
|
||||
// call here.
|
||||
visit::walk_path(self, &tr.path);
|
||||
intravisit::walk_path(self, &tr.path);
|
||||
|
||||
// Those in 3. are warned with this call.
|
||||
for impl_item in impl_items {
|
||||
@ -1370,21 +1399,21 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
hir::ImplItemKind::Const(..) => {
|
||||
if self.item_is_public(&impl_item.id, impl_item.vis) {
|
||||
found_pub_static = true;
|
||||
visit::walk_impl_item(self, impl_item);
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
}
|
||||
hir::ImplItemKind::Method(ref sig, _) => {
|
||||
if sig.explicit_self.node == hir::SelfStatic &&
|
||||
self.item_is_public(&impl_item.id, impl_item.vis) {
|
||||
found_pub_static = true;
|
||||
visit::walk_impl_item(self, impl_item);
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if found_pub_static {
|
||||
visit::walk_generics(self, g)
|
||||
intravisit::walk_generics(self, g)
|
||||
}
|
||||
}
|
||||
return
|
||||
@ -1407,7 +1436,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
// public signatures, i.e. things that we're interested in for
|
||||
// this visitor.
|
||||
debug!("VisiblePrivateTypesVisitor entering item {:?}", item);
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_generics(&mut self, generics: &hir::Generics) {
|
||||
@ -1433,7 +1462,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
|
||||
fn visit_foreign_item(&mut self, item: &hir::ForeignItem) {
|
||||
if self.exported_items.contains(&item.id) {
|
||||
visit::walk_foreign_item(self, item)
|
||||
intravisit::walk_foreign_item(self, item)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1446,13 +1475,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
"private type in exported type signature");
|
||||
}
|
||||
}
|
||||
visit::walk_ty(self, t)
|
||||
intravisit::walk_ty(self, t)
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics, item_id: ast::NodeId) {
|
||||
if self.exported_items.contains(&v.node.data.id()) {
|
||||
self.in_variant = true;
|
||||
visit::walk_variant(self, v, g, item_id);
|
||||
intravisit::walk_variant(self, v, g, item_id);
|
||||
self.in_variant = false;
|
||||
}
|
||||
}
|
||||
@ -1462,7 +1491,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
hir::NamedField(_, vis) | hir::UnnamedField(vis) => vis
|
||||
};
|
||||
if vis == hir::Public || self.in_variant {
|
||||
visit::walk_struct_field(self, s);
|
||||
intravisit::walk_struct_field(self, s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1489,14 +1518,15 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
tcx: tcx,
|
||||
in_block: false,
|
||||
};
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
|
||||
// Figure out who everyone's parent is
|
||||
let mut visitor = ParentVisitor {
|
||||
tcx: tcx,
|
||||
parents: NodeMap(),
|
||||
curparent: ast::DUMMY_NODE_ID,
|
||||
};
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
|
||||
// Use the parent map to check the privacy of everything
|
||||
let mut visitor = PrivacyVisitor {
|
||||
@ -1506,7 +1536,7 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
parents: visitor.parents,
|
||||
external_exports: external_exports,
|
||||
};
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
|
||||
tcx.sess.abort_if_errors();
|
||||
|
||||
@ -1524,7 +1554,7 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
visitor.public_items.insert(ast::CRATE_NODE_ID);
|
||||
loop {
|
||||
let before = (visitor.exported_items.len(), visitor.public_items.len());
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
let after = (visitor.exported_items.len(), visitor.public_items.len());
|
||||
if after == before {
|
||||
break
|
||||
@ -1540,7 +1570,7 @@ pub fn check_crate(tcx: &ty::ctxt,
|
||||
public_items: &public_items,
|
||||
in_variant: false,
|
||||
};
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
}
|
||||
return (exported_items, public_items);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ use rustc_front::hir::StmtDecl;
|
||||
use rustc_front::hir::UnnamedField;
|
||||
use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use rustc_front::hir::Visibility;
|
||||
use rustc_front::visit::{self, Visitor};
|
||||
use rustc_front::intravisit::{self, Visitor};
|
||||
|
||||
use std::mem::replace;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
@ -111,7 +111,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
builder: self,
|
||||
parent: parent,
|
||||
};
|
||||
visit::walk_crate(&mut visitor, krate);
|
||||
intravisit::walk_crate(&mut visitor, krate);
|
||||
}
|
||||
|
||||
/// Adds a new child item to the module definition of the parent node and
|
||||
@ -1051,10 +1051,14 @@ struct BuildReducedGraphVisitor<'a, 'b: 'a, 'tcx: 'b> {
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.builder.resolver.ast_map.expect_item(item.id))
|
||||
}
|
||||
|
||||
fn visit_item(&mut self, item: &Item) {
|
||||
let p = self.builder.build_reduced_graph_for_item(item, &self.parent);
|
||||
let old_parent = replace(&mut self.parent, p);
|
||||
visit::walk_item(self, item);
|
||||
intravisit::walk_item(self, item);
|
||||
self.parent = old_parent;
|
||||
}
|
||||
|
||||
@ -1065,7 +1069,7 @@ impl<'a, 'b, 'v, 'tcx> Visitor<'v> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
|
||||
fn visit_block(&mut self, block: &Block) {
|
||||
let np = self.builder.build_reduced_graph_for_block(block, &self.parent);
|
||||
let old_parent = replace(&mut self.parent, np);
|
||||
visit::walk_block(self, block);
|
||||
intravisit::walk_block(self, block);
|
||||
self.parent = old_parent;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ use syntax::parse::token::{self, special_names, special_idents};
|
||||
use syntax::ptr::P;
|
||||
use syntax::codemap::{self, Span, Pos};
|
||||
|
||||
use rustc_front::visit::{self, FnKind, Visitor};
|
||||
use rustc_front::intravisit::{self, FnKind, Visitor};
|
||||
use rustc_front::hir;
|
||||
use rustc_front::hir::{Arm, BindByRef, BindByValue, BindingMode, Block};
|
||||
use rustc_front::hir::Crate;
|
||||
@ -541,6 +541,9 @@ enum NameDefinition {
|
||||
}
|
||||
|
||||
impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
|
||||
fn visit_nested_item(&mut self, item: hir::ItemId) {
|
||||
self.visit_item(self.ast_map.expect_item(item.id))
|
||||
}
|
||||
fn visit_item(&mut self, item: &Item) {
|
||||
execute_callback!(hir_map::Node::NodeItem(item), self);
|
||||
self.resolve_item(item);
|
||||
@ -573,7 +576,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
|
||||
// error already reported
|
||||
}
|
||||
}
|
||||
visit::walk_poly_trait_ref(self, tref, m);
|
||||
intravisit::walk_poly_trait_ref(self, tref, m);
|
||||
}
|
||||
fn visit_variant(&mut self,
|
||||
variant: &hir::Variant,
|
||||
@ -583,11 +586,11 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
|
||||
if let Some(ref dis_expr) = variant.node.disr_expr {
|
||||
// resolve the discriminator expr as a constant
|
||||
self.with_constant_rib(|this| {
|
||||
this.visit_expr(&**dis_expr);
|
||||
this.visit_expr(dis_expr);
|
||||
});
|
||||
}
|
||||
|
||||
// `visit::walk_variant` without the discriminant expression.
|
||||
// `intravisit::walk_variant` without the discriminant expression.
|
||||
self.visit_variant_data(&variant.node.data,
|
||||
variant.node.name,
|
||||
generics,
|
||||
@ -603,7 +606,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
|
||||
ForeignItemStatic(..) => NoTypeParameters,
|
||||
};
|
||||
self.with_type_parameter_rib(type_parameters, |this| {
|
||||
visit::walk_foreign_item(this, foreign_item);
|
||||
intravisit::walk_foreign_item(this, foreign_item);
|
||||
});
|
||||
}
|
||||
fn visit_fn(&mut self,
|
||||
@ -2047,7 +2050,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
fn resolve_crate(&mut self, krate: &hir::Crate) {
|
||||
debug!("(resolving crate) starting");
|
||||
|
||||
visit::walk_crate(self, krate);
|
||||
intravisit::walk_crate(self, krate);
|
||||
}
|
||||
|
||||
fn check_if_primitive_type_name(&self, name: Name, span: Span) {
|
||||
@ -2071,11 +2074,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
self.check_if_primitive_type_name(name, item.span);
|
||||
|
||||
self.with_type_parameter_rib(HasTypeParameters(generics, TypeSpace, ItemRibKind),
|
||||
|this| visit::walk_item(this, item));
|
||||
|this| intravisit::walk_item(this, item));
|
||||
}
|
||||
ItemFn(_, _, _, _, ref generics, _) => {
|
||||
self.with_type_parameter_rib(HasTypeParameters(generics, FnSpace, ItemRibKind),
|
||||
|this| visit::walk_item(this, item));
|
||||
|this| intravisit::walk_item(this, item));
|
||||
}
|
||||
|
||||
ItemDefaultImpl(_, ref trait_ref) => {
|
||||
@ -2110,10 +2113,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
// expression in a provided default.
|
||||
if default.is_some() {
|
||||
this.with_constant_rib(|this| {
|
||||
visit::walk_trait_item(this, trait_item)
|
||||
intravisit::walk_trait_item(this, trait_item)
|
||||
});
|
||||
} else {
|
||||
visit::walk_trait_item(this, trait_item)
|
||||
intravisit::walk_trait_item(this, trait_item)
|
||||
}
|
||||
}
|
||||
hir::MethodTraitItem(ref sig, _) => {
|
||||
@ -2122,14 +2125,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
FnSpace,
|
||||
MethodRibKind);
|
||||
this.with_type_parameter_rib(type_parameters, |this| {
|
||||
visit::walk_trait_item(this, trait_item)
|
||||
intravisit::walk_trait_item(this, trait_item)
|
||||
});
|
||||
}
|
||||
hir::TypeTraitItem(..) => {
|
||||
this.check_if_primitive_type_name(trait_item.name,
|
||||
trait_item.span);
|
||||
this.with_type_parameter_rib(NoTypeParameters, |this| {
|
||||
visit::walk_trait_item(this, trait_item)
|
||||
intravisit::walk_trait_item(this, trait_item)
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -2140,13 +2143,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
|
||||
ItemMod(_) | ItemForeignMod(_) => {
|
||||
self.with_scope(Some(name), |this| {
|
||||
visit::walk_item(this, item);
|
||||
intravisit::walk_item(this, item);
|
||||
});
|
||||
}
|
||||
|
||||
ItemConst(..) | ItemStatic(..) => {
|
||||
self.with_constant_rib(|this| {
|
||||
visit::walk_item(this, item);
|
||||
intravisit::walk_item(this, item);
|
||||
});
|
||||
}
|
||||
|
||||
@ -2283,10 +2286,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
|
||||
debug!("(resolving function) recorded argument");
|
||||
}
|
||||
visit::walk_fn_ret_ty(self, &declaration.output);
|
||||
intravisit::walk_fn_ret_ty(self, &declaration.output);
|
||||
|
||||
// Resolve the function body.
|
||||
self.visit_block(&*block);
|
||||
self.visit_block(block);
|
||||
|
||||
debug!("(resolving function) leaving function");
|
||||
|
||||
@ -2347,7 +2350,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
visit::walk_generics(self, generics);
|
||||
intravisit::walk_generics(self, generics);
|
||||
}
|
||||
|
||||
fn with_current_self_type<T, F>(&mut self, self_type: &Ty, f: F) -> T
|
||||
@ -2374,7 +2377,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
new_val = Some((path_res.base_def.def_id(), trait_ref.clone()));
|
||||
new_id = Some(path_res.base_def.def_id());
|
||||
}
|
||||
visit::walk_trait_ref(self, trait_ref);
|
||||
intravisit::walk_trait_ref(self, trait_ref);
|
||||
}
|
||||
let original_trait_ref = replace(&mut self.current_trait_ref, new_val);
|
||||
let result = f(self, new_id);
|
||||
@ -2427,7 +2430,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
impl_item.span,
|
||||
|n, s| ResolutionError::ConstNotMemberOfTrait(n, s));
|
||||
this.with_constant_rib(|this| {
|
||||
visit::walk_impl_item(this, impl_item);
|
||||
intravisit::walk_impl_item(this, impl_item);
|
||||
});
|
||||
}
|
||||
hir::ImplItemKind::Method(ref sig, _) => {
|
||||
@ -2444,7 +2447,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
FnSpace,
|
||||
MethodRibKind);
|
||||
this.with_type_parameter_rib(type_parameters, |this| {
|
||||
visit::walk_impl_item(this, impl_item);
|
||||
intravisit::walk_impl_item(this, impl_item);
|
||||
});
|
||||
}
|
||||
hir::ImplItemKind::Type(ref ty) => {
|
||||
@ -2583,7 +2586,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
let mut found_non_item = false;
|
||||
for statement in &block.stmts {
|
||||
if let hir::StmtDecl(ref declaration, _) = statement.node {
|
||||
if let hir::DeclItem(ref i) = declaration.node {
|
||||
if let hir::DeclItem(i) = declaration.node {
|
||||
let i = self.ast_map.expect_item(i.id);
|
||||
match i.node {
|
||||
ItemExternCrate(_) | ItemUse(_) if found_non_item => {
|
||||
span_err!(self.session,
|
||||
@ -2602,7 +2606,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// Descend into the block.
|
||||
visit::walk_block(self, block);
|
||||
intravisit::walk_block(self, block);
|
||||
|
||||
// Move back up.
|
||||
if !self.resolved {
|
||||
@ -2623,7 +2627,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
// `<T>::a::b::c` is resolved by typeck alone.
|
||||
TypecheckRequired => {
|
||||
// Resolve embedded types.
|
||||
visit::walk_ty(self, ty);
|
||||
intravisit::walk_ty(self, ty);
|
||||
return;
|
||||
}
|
||||
ResolveAttempt(resolution) => resolution,
|
||||
@ -2674,7 +2678,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
_ => {}
|
||||
}
|
||||
// Resolve embedded types.
|
||||
visit::walk_ty(self, ty);
|
||||
intravisit::walk_ty(self, ty);
|
||||
}
|
||||
|
||||
fn resolve_pattern(&mut self,
|
||||
@ -2862,7 +2866,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
&path.segments.last().unwrap().identifier.name.as_str())
|
||||
);
|
||||
}
|
||||
visit::walk_path(self, path);
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
|
||||
PatQPath(ref qself, ref path) => {
|
||||
@ -2883,7 +2887,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
.name;
|
||||
let traits = self.get_traits_containing_item(const_name);
|
||||
self.trait_map.insert(pattern.id, traits);
|
||||
visit::walk_pat(self, pattern);
|
||||
intravisit::walk_pat(self, pattern);
|
||||
return true;
|
||||
}
|
||||
ResolveAttempt(resolution) => resolution,
|
||||
@ -2915,7 +2919,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
.name
|
||||
.as_str()));
|
||||
}
|
||||
visit::walk_pat(self, pattern);
|
||||
intravisit::walk_pat(self, pattern);
|
||||
}
|
||||
|
||||
PatStruct(ref path, _, _) => {
|
||||
@ -2933,11 +2937,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
);
|
||||
}
|
||||
}
|
||||
visit::walk_path(self, path);
|
||||
intravisit::walk_path(self, path);
|
||||
}
|
||||
|
||||
PatLit(_) | PatRange(..) => {
|
||||
visit::walk_pat(self, pattern);
|
||||
intravisit::walk_pat(self, pattern);
|
||||
}
|
||||
|
||||
_ => {
|
||||
@ -3665,7 +3669,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
let method_name = path.segments.last().unwrap().identifier.name;
|
||||
let traits = self.get_traits_containing_item(method_name);
|
||||
self.trait_map.insert(expr.id, traits);
|
||||
visit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr);
|
||||
return;
|
||||
}
|
||||
ResolveAttempt(resolution) => resolution,
|
||||
@ -3777,7 +3781,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
visit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
ExprStruct(ref path, _, _) => {
|
||||
@ -3797,7 +3801,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
visit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
ExprLoop(_, Some(label)) | ExprWhile(_, _, Some(label)) => {
|
||||
@ -3810,7 +3814,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
rib.bindings.insert(renamed, def_like);
|
||||
}
|
||||
|
||||
visit::walk_expr(this, expr);
|
||||
intravisit::walk_expr(this, expr);
|
||||
})
|
||||
}
|
||||
|
||||
@ -3838,7 +3842,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
|
||||
_ => {
|
||||
visit::walk_expr(self, expr);
|
||||
intravisit::walk_expr(self, expr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user