Skip to content

Commit

Permalink
Fill in some missing parts in the default HIR visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Sep 28, 2015
1 parent eedb951 commit 4744d56
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 370 deletions.
4 changes: 2 additions & 2 deletions src/librustc/front/map/mod.rs
Expand Up @@ -912,12 +912,12 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
self.parent_node = parent_node;
}

fn visit_lifetime_ref(&mut self, lifetime: &'ast Lifetime) {
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
self.insert(lifetime.id, NodeLifetime(lifetime));
}

fn visit_lifetime_def(&mut self, def: &'ast LifetimeDef) {
self.visit_lifetime_ref(&def.lifetime);
self.visit_lifetime(&def.lifetime);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/librustc/lint/context.rs
Expand Up @@ -745,12 +745,8 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
});
}

fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<hir::Lifetime>) {
run_lints!(self, check_opt_lifetime_ref, late_passes, sp, lt);
}

fn visit_lifetime_ref(&mut self, lt: &hir::Lifetime) {
run_lints!(self, check_lifetime_ref, late_passes, lt);
fn visit_lifetime(&mut self, lt: &hir::Lifetime) {
run_lints!(self, check_lifetime, late_passes, lt);
}

fn visit_lifetime_def(&mut self, lt: &hir::LifetimeDef) {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/lint/mod.rs
Expand Up @@ -156,8 +156,7 @@ pub trait LateLintPass: LintPass {
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
fn check_opt_lifetime_ref(&mut self, _: &LateContext, _: Span, _: &Option<hir::Lifetime>) { }
fn check_lifetime_ref(&mut self, _: &LateContext, _: &hir::Lifetime) { }
fn check_lifetime(&mut self, _: &LateContext, _: &hir::Lifetime) { }
fn check_lifetime_def(&mut self, _: &LateContext, _: &hir::LifetimeDef) { }
fn check_explicit_self(&mut self, _: &LateContext, _: &hir::ExplicitSelf) { }
fn check_path(&mut self, _: &LateContext, _: &hir::Path, _: ast::NodeId) { }
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/metadata/creader.rs
Expand Up @@ -481,6 +481,12 @@ impl<'a> CrateReader<'a> {
};
let span = mk_sp(lo, p.last_span.hi);
p.abort_if_errors();

// Mark the attrs as used
for attr in &attrs {
attr::mark_used(attr);
}

macros.push(ast::MacroDef {
ident: ast::Ident::with_empty_ctxt(name),
attrs: attrs,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Expand Up @@ -705,7 +705,7 @@ fn resolve_block(visitor: &mut RegionResolutionVisitor, blk: &hir::Block) {
}
visitor.visit_stmt(&**statement)
}
visit::walk_expr_opt(visitor, &blk.expr)
walk_list!(visitor, visit_expr, &blk.expr);
}

visitor.cx = prev_cx;
Expand Down
23 changes: 11 additions & 12 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -195,7 +195,6 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
fn visit_ty(&mut self, ty: &hir::Ty) {
match ty.node {
hir::TyBareFn(ref c) => {
visit::walk_lifetime_decls_helper(self, &c.lifetimes);
self.with(LateScope(&c.lifetimes, self.scope), |old_scope, this| {
// a bare fn has no bounds, so everything
// contained within is scoped within its binder.
Expand Down Expand Up @@ -245,7 +244,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
|_, this| visit::walk_block(this, b));
}

fn visit_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
if lifetime_ref.name == special_idents::static_lifetime.name {
self.insert_lifetime(lifetime_ref, DefStaticRegion);
return;
Expand All @@ -255,7 +254,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {

fn visit_generics(&mut self, generics: &hir::Generics) {
for ty_param in generics.ty_params.iter() {
visit::walk_ty_param_bounds_helper(self, &ty_param.bounds);
walk_list!(self, visit_ty_param_bound, &ty_param.bounds);
match ty_param.default {
Some(ref ty) => self.visit_ty(&**ty),
None => {}
Expand All @@ -273,22 +272,22 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
|old_scope, this| {
this.check_lifetime_defs(old_scope, bound_lifetimes);
this.visit_ty(&**bounded_ty);
visit::walk_ty_param_bounds_helper(this, bounds);
walk_list!(this, visit_ty_param_bound, bounds);
});
self.trait_ref_hack = false;
result
} else {
self.visit_ty(&**bounded_ty);
visit::walk_ty_param_bounds_helper(self, bounds);
walk_list!(self, visit_ty_param_bound, bounds);
}
}
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate{ref lifetime,
ref bounds,
.. }) => {

self.visit_lifetime_ref(lifetime);
self.visit_lifetime(lifetime);
for bound in bounds {
self.visit_lifetime_ref(bound);
self.visit_lifetime(bound);
}
}
&hir::WherePredicate::EqPredicate(hir::WhereEqPredicate{ id,
Expand Down Expand Up @@ -799,23 +798,23 @@ fn early_bound_lifetime_names(generics: &hir::Generics) -> Vec<ast::Name> {
FreeLifetimeCollector { early_bound: &mut early_bound,
late_bound: &mut late_bound };
for ty_param in generics.ty_params.iter() {
visit::walk_ty_param_bounds_helper(&mut collector, &ty_param.bounds);
walk_list!(&mut collector, visit_ty_param_bound, &ty_param.bounds);
}
for predicate in &generics.where_clause.predicates {
match predicate {
&hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate{ref bounds,
ref bounded_ty,
..}) => {
collector.visit_ty(&**bounded_ty);
visit::walk_ty_param_bounds_helper(&mut collector, bounds);
walk_list!(&mut collector, visit_ty_param_bound, bounds);
}
&hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate{ref lifetime,
ref bounds,
..}) => {
collector.visit_lifetime_ref(lifetime);
collector.visit_lifetime(lifetime);

for bound in bounds {
collector.visit_lifetime_ref(bound);
collector.visit_lifetime(bound);
}
}
&hir::WherePredicate::EqPredicate(_) => unimplemented!()
Expand Down Expand Up @@ -843,7 +842,7 @@ fn early_bound_lifetime_names(generics: &hir::Generics) -> Vec<ast::Name> {
}

impl<'a, 'v> Visitor<'v> for FreeLifetimeCollector<'a> {
fn visit_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) {
shuffle(self.early_bound, self.late_bound,
lifetime_ref.name);
}
Expand Down
18 changes: 3 additions & 15 deletions src/librustc_back/svh.rs
Expand Up @@ -177,7 +177,7 @@ mod svh_visitor {
SawIdent(token::InternedString),
SawStructDef(token::InternedString),

SawLifetimeRef(token::InternedString),
SawLifetime(token::InternedString),
SawLifetimeDef(token::InternedString),

SawMod,
Expand All @@ -193,7 +193,6 @@ mod svh_visitor {
SawVariant,
SawExplicitSelf,
SawPath,
SawOptLifetimeRef,
SawBlock,
SawPat,
SawLocal,
Expand Down Expand Up @@ -316,17 +315,6 @@ mod svh_visitor {
visit::walk_variant(self, v, g)
}

fn visit_opt_lifetime_ref(&mut self, _: Span, l: &Option<Lifetime>) {
SawOptLifetimeRef.hash(self.st);
// (This is a strange method in the visitor trait, in that
// it does not expose a walk function to do the subroutine
// calls.)
match *l {
Some(ref l) => self.visit_lifetime_ref(l),
None => ()
}
}

// All of the remaining methods just record (in the hash
// SipHasher) that the visitor saw that particular variant
// (with its payload), and continue walking as the default
Expand All @@ -345,8 +333,8 @@ mod svh_visitor {
SawIdent(name.as_str()).hash(self.st);
}

fn visit_lifetime_ref(&mut self, l: &Lifetime) {
SawLifetimeRef(l.name.as_str()).hash(self.st);
fn visit_lifetime(&mut self, l: &Lifetime) {
SawLifetime(l.name.as_str()).hash(self.st);
}

fn visit_lifetime_def(&mut self, l: &LifetimeDef) {
Expand Down
7 changes: 7 additions & 0 deletions src/librustc_front/hir.rs
Expand Up @@ -1054,6 +1054,13 @@ impl PathListItem_ {
}
}

pub fn name(&self) -> Option<Name> {
match *self {
PathListIdent { name, .. } => Some(name),
PathListMod { .. } => None,
}
}

pub fn rename(&self) -> Option<Name> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_front/util.rs
Expand Up @@ -303,12 +303,12 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>
visit::walk_impl_item(self, ii);
}

fn visit_lifetime_ref(&mut self, lifetime: &Lifetime) {
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
self.operation.visit_id(lifetime.id);
}

fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
self.visit_lifetime_ref(&def.lifetime);
self.visit_lifetime(&def.lifetime);
}

fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {
Expand Down

0 comments on commit 4744d56

Please sign in to comment.