Split nested_visit_mode function off from nested_visit_map
... and make the latter mandatory to implement.
This commit is contained in:
parent
725cffb1d5
commit
f0ce5bb66b
35 changed files with 160 additions and 110 deletions
|
|
@ -193,6 +193,8 @@ fn build_nodeid_to_index(decl: Option<&hir::FnDecl>,
|
|||
let mut formals = Formals { entry: entry, index: index };
|
||||
intravisit::walk_fn_decl(&mut formals, decl);
|
||||
impl<'a, 'v> intravisit::Visitor<'v> for Formals<'a> {
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'v>> { None }
|
||||
|
||||
fn visit_pat(&mut self, p: &hir::Pat) {
|
||||
self.index.entry(p.id).or_insert(vec![]).push(self.entry);
|
||||
intravisit::walk_pat(self, p)
|
||||
|
|
|
|||
|
|
@ -221,8 +221,8 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
fn visit_variant_data(&mut self, def: &'tcx hir::VariantData, _: ast::Name,
|
||||
|
|
@ -510,10 +510,12 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
|||
/// 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 nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::All))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
fn nested_visit_mode(&mut self) -> NestedVisitMode { NestedVisitMode::All }
|
||||
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item) {
|
||||
if self.should_warn_about_item(item) {
|
||||
self.warn_dead_code(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use syntax::ast;
|
|||
use syntax_pos::Span;
|
||||
use hir::{self, PatKind};
|
||||
use hir::def::Def;
|
||||
use hir::intravisit::{self, FnKind, Visitor, NestedVisitMode};
|
||||
use hir::intravisit::{self, FnKind, Visitor};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct UnsafeContext {
|
||||
|
|
@ -93,8 +93,8 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
fn visit_fn(&mut self, fn_kind: FnKind<'tcx>, fn_decl: &'tcx hir::FnDecl,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ use ty::layout::{LayoutError, Pointer, SizeSkeleton};
|
|||
use syntax::abi::Abi::RustIntrinsic;
|
||||
use syntax::ast;
|
||||
use syntax_pos::Span;
|
||||
use hir::intravisit::{self, Visitor, FnKind, NestedVisitMode};
|
||||
use hir::intravisit::{self, Visitor, FnKind};
|
||||
use hir;
|
||||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
|
||||
|
|
@ -117,8 +117,8 @@ impl<'a, 'gcx, 'tcx> ExprVisitor<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ItemVisitor<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
// const, static and N in [T; N].
|
||||
|
|
@ -163,8 +163,8 @@ impl<'a, 'tcx> Visitor<'tcx> for ItemVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for ExprVisitor<'a, 'gcx, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'gcx>, NestedVisitMode)> {
|
||||
Some((&self.infcx.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'gcx>> {
|
||||
Some(&self.infcx.tcx.map)
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ use syntax_pos::Span;
|
|||
use hir::Expr;
|
||||
use hir;
|
||||
use hir::print::{expr_to_string, block_to_string};
|
||||
use hir::intravisit::{self, Visitor, FnKind, NestedVisitMode};
|
||||
use hir::intravisit::{self, Visitor, FnKind};
|
||||
|
||||
/// For use with `propagate_through_loop`.
|
||||
enum LoopKind<'a> {
|
||||
|
|
@ -183,8 +183,8 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt) -> String {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for IrMaps<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
|
||||
b: hir::ExprId, s: Span, id: NodeId) {
|
||||
|
|
@ -352,8 +352,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for Liveness<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.ir.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.ir.tcx.map)
|
||||
}
|
||||
fn visit_fn(&mut self, _: FnKind<'tcx>, _: &'tcx hir::FnDecl,
|
||||
_: hir::ExprId, _: Span, _: NodeId) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use syntax::abi::Abi;
|
|||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use hir;
|
||||
use hir::intravisit::{Visitor, NestedVisitMode};
|
||||
use hir::intravisit::{Visitor};
|
||||
use hir::itemlikevisit::ItemLikeVisitor;
|
||||
use hir::intravisit;
|
||||
|
||||
|
|
@ -89,8 +89,8 @@ struct ReachableContext<'a, 'tcx: 'a> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ use syntax::ast::{self, NodeId};
|
|||
use syntax_pos::Span;
|
||||
|
||||
use hir;
|
||||
use hir::intravisit::{self, Visitor, FnKind, NestedVisitMode};
|
||||
use hir::intravisit::{self, Visitor, FnKind};
|
||||
use hir::{Block, Item, FnDecl, Arm, Pat, PatKind, Stmt, Expr, Local};
|
||||
|
||||
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
|
||||
|
|
@ -1170,8 +1170,8 @@ impl<'ast, 'a> RegionResolutionVisitor<'ast, 'a> {
|
|||
}
|
||||
|
||||
impl<'ast, 'a> Visitor<'ast> for RegionResolutionVisitor<'ast, 'a> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'ast>, NestedVisitMode)> {
|
||||
Some((&self.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'ast>> {
|
||||
Some(&self.map)
|
||||
}
|
||||
|
||||
fn visit_block(&mut self, b: &'ast Block) {
|
||||
|
|
|
|||
|
|
@ -132,10 +132,12 @@ pub fn krate(sess: &Session,
|
|||
impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||
// Override the nested functions -- lifetimes follow lexical scope,
|
||||
// so it's convenient to walk the tree in lexical order.
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.hir_map, NestedVisitMode::All))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.hir_map)
|
||||
}
|
||||
|
||||
fn nested_visit_mode(&mut self) -> NestedVisitMode { NestedVisitMode::All }
|
||||
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item) {
|
||||
// Save labels for nested items.
|
||||
let saved_labels_in_fn = replace(&mut self.labels_in_fn, vec![]);
|
||||
|
|
@ -423,6 +425,8 @@ fn extract_labels(ctxt: &mut LifetimeContext, b: hir::ExprId) {
|
|||
return;
|
||||
|
||||
impl<'v, 'a> Visitor<'v> for GatherLabels<'a> {
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'v>> { None }
|
||||
|
||||
fn visit_expr(&mut self, ex: &'v hir::Expr) {
|
||||
// do not recurse into closures defined in the block
|
||||
// since they are treated as separate fns from the POV of
|
||||
|
|
@ -938,6 +942,8 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
|
|||
}
|
||||
|
||||
impl<'v> Visitor<'v> for ConstrainedCollector {
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'v>> { None }
|
||||
|
||||
fn visit_ty(&mut self, ty: &'v hir::Ty) {
|
||||
match ty.node {
|
||||
hir::TyPath(hir::QPath::Resolved(Some(_), _)) |
|
||||
|
|
@ -975,6 +981,8 @@ fn insert_late_bound_lifetimes(map: &mut NamedRegionMap,
|
|||
}
|
||||
|
||||
impl<'v> Visitor<'v> for AllCollector {
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'v>> { None }
|
||||
|
||||
fn visit_lifetime(&mut self, lifetime_ref: &'v hir::Lifetime) {
|
||||
self.regions.insert(lifetime_ref.name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -234,10 +234,12 @@ impl<'a, 'tcx> Visitor<'tcx> 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 nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::All))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
fn nested_visit_mode(&mut self) -> NestedVisitMode { NestedVisitMode::All }
|
||||
|
||||
fn visit_item(&mut self, i: &'tcx Item) {
|
||||
let orig_in_trait_impl = self.in_trait_impl;
|
||||
let mut kind = AnnotationKind::Required;
|
||||
|
|
@ -534,10 +536,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
||||
fn nested_visit_map(&mut self) -> Option<(&hir::map::Map<'tcx>, NestedVisitMode)> {
|
||||
Some((&self.tcx.map, NestedVisitMode::OnlyBodies))
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'tcx>> {
|
||||
Some(&self.tcx.map)
|
||||
}
|
||||
|
||||
fn nested_visit_mode(&mut self) -> NestedVisitMode { NestedVisitMode::OnlyBodies }
|
||||
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item) {
|
||||
match item.node {
|
||||
hir::ItemExternCrate(_) => {
|
||||
|
|
|
|||
|
|
@ -125,6 +125,8 @@ impl<'a> Context<'a> {
|
|||
}
|
||||
|
||||
impl<'a, 'v> Visitor<'v> for Context<'a> {
|
||||
fn nested_visit_map(&mut self) -> Option<&hir::map::Map<'v>> { None }
|
||||
|
||||
fn visit_foreign_item(&mut self, i: &hir::ForeignItem) {
|
||||
if let Some(lang_item) = lang_items::extract(&i.attrs) {
|
||||
self.register(&lang_item.as_str(), i.span);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue