提交 4744d568 编写于 作者: V Vadim Petrochenkov

Fill in some missing parts in the default HIR visitor

上级 eedb9510
......@@ -912,12 +912,12 @@ fn visit_block(&mut self, block: &'ast Block) {
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);
}
}
......
......@@ -745,12 +745,8 @@ fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
});
}
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) {
......
......@@ -156,8 +156,7 @@ fn check_struct_def_post(&mut self, _: &LateContext,
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) { }
......
......@@ -481,6 +481,12 @@ pub fn read_exported_macros(&mut self, item: &ast::Item) -> Vec<ast::MacroDef> {
};
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,
......
......@@ -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;
......
......@@ -195,7 +195,6 @@ fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v hir::FnDecl,
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.
......@@ -245,7 +244,7 @@ fn visit_block(&mut self, b: &hir::Block) {
|_, 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;
......@@ -255,7 +254,7 @@ fn visit_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
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 => {}
......@@ -273,22 +272,22 @@ fn visit_generics(&mut self, generics: &hir::Generics) {
|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,
......@@ -799,7 +798,7 @@ 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 {
......@@ -807,15 +806,15 @@ fn early_bound_lifetime_names(generics: &hir::Generics) -> Vec<ast::Name> {
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!()
......@@ -843,7 +842,7 @@ struct FreeLifetimeCollector<'a> {
}
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);
}
......
......@@ -177,7 +177,7 @@ enum SawAbiComponent<'a> {
SawIdent(token::InternedString),
SawStructDef(token::InternedString),
SawLifetimeRef(token::InternedString),
SawLifetime(token::InternedString),
SawLifetimeDef(token::InternedString),
SawMod,
......@@ -193,7 +193,6 @@ enum SawAbiComponent<'a> {
SawVariant,
SawExplicitSelf,
SawPath,
SawOptLifetimeRef,
SawBlock,
SawPat,
SawLocal,
......@@ -316,17 +315,6 @@ fn visit_variant(&mut self, v: &Variant, g: &Generics) {
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
......@@ -345,8 +333,8 @@ fn visit_name(&mut self, _: Span, name: Name) {
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) {
......
......@@ -1054,6 +1054,13 @@ pub fn id(&self) -> NodeId {
}
}
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
......
......@@ -303,12 +303,12 @@ fn visit_impl_item(&mut self, ii: &hir::ImplItem) {
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) {
......
此差异已折叠。
......@@ -2158,7 +2158,7 @@ fn resolve_item(&mut self, item: &Item) {
|this| {
this.with_self_rib(DefSelfTy(Some(DefId::local(item.id)), None), |this| {
this.visit_generics(generics);
visit::walk_ty_param_bounds_helper(this, bounds);
walk_list!(this, visit_ty_param_bound, bounds);
for trait_item in trait_items {
match trait_item.node {
......@@ -2542,10 +2542,10 @@ fn check_trait_item<F>(&self, name: Name, span: Span, err: F)
fn resolve_local(&mut self, local: &Local) {
// Resolve the type.
visit::walk_ty_opt(self, &local.ty);
walk_list!(self, visit_ty, &local.ty);
// Resolve the initializer.
visit::walk_expr_opt(self, &local.init);
walk_list!(self, visit_expr, &local.init);
// Resolve the pattern.
self.resolve_pattern(&*local.pat,
......@@ -2622,7 +2622,7 @@ fn resolve_arm(&mut self, arm: &Arm) {
// pat_idents are variants
self.check_consistent_bindings(arm);
visit::walk_expr_opt(self, &arm.guard);
walk_list!(self, visit_expr, &arm.guard);
self.visit_expr(&*arm.body);
if !self.resolved {
......
......@@ -1167,7 +1167,7 @@ fn has_nested_returns(tcx: &ty::ctxt, cfg: &cfg::CFG, blk_id: ast::NodeId) -> bo
}
Some(hir_map::NodeBlock(blk)) if blk.id == blk_id => {
let mut visitor = FindNestedReturn::new();
visit::walk_expr_opt(&mut visitor, &blk.expr);
walk_list!(&mut visitor, visit_expr, &blk.expr);
if visitor.found {
return true;
}
......
......@@ -376,6 +376,11 @@ fn visit_ty(&mut self, t: &'tcx hir::Ty) {
hir::TyFixedLengthVec(_, ref expr) => {
check_const_in_type(self.ccx, &**expr, self.ccx.tcx.types.usize);
}
hir::TyBareFn(ref function_declaration) => {
visit::walk_fn_decl_nopat(self, &function_declaration.decl);
walk_list!(self, visit_lifetime_def, &function_declaration.lifetimes);
return
}
_ => {}
}
......@@ -560,6 +565,10 @@ fn visit_ty(&mut self, t: &'tcx hir::Ty) {
self.visit_ty(&**ty);
check_expr_with_hint(self.fcx, &**count_expr, self.fcx.tcx().types.usize);
}
hir::TyBareFn(ref function_declaration) => {
visit::walk_fn_decl_nopat(self, &function_declaration.decl);
walk_list!(self, visit_lifetime_def, &function_declaration.lifetimes);
}
_ => visit::walk_ty(self, t)
}
}
......
......@@ -225,6 +225,10 @@ fn visit_ty(&mut self, t: &hir::Ty) {
self.visit_ty(&**ty);
write_ty_to_tcx(self.tcx(), count_expr.id, self.tcx().types.usize);
}
hir::TyBareFn(ref function_declaration) => {
visit::walk_fn_decl_nopat(self, &function_declaration.decl);
walk_list!(self, visit_lifetime_def, &function_declaration.lifetimes);
}
_ => visit::walk_ty(self, t)
}
}
......
......@@ -131,7 +131,7 @@ fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
#[macro_export]
macro_rules! walk_list {
($visitor: ident, $method: ident, $list: expr) => {
($visitor: expr, $method: ident, $list: expr) => {
for elem in $list {
$visitor.$method(elem)
}
......@@ -530,23 +530,22 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics
}
}
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) {
if let Return(ref output_ty) = *ret_ty {
visitor.visit_ty(output_ty)
}
}
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) {
for argument in &function_declaration.inputs {
visitor.visit_pat(&argument.pat);
visitor.visit_ty(&argument.ty)
}
if let Return(ref output_ty) = function_declaration.output {
visitor.visit_ty(output_ty)
}
walk_fn_ret_ty(visitor, &function_declaration.output)
}
pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
function_kind: FnKind<'v>,
function_declaration: &'v FnDecl,
function_body: &'v Block,
_span: Span) {
walk_fn_decl(visitor, function_declaration);
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V,
function_kind: FnKind<'v>) {
match function_kind {
FnKind::ItemFn(_, generics, _, _, _, _) => {
visitor.visit_generics(generics);
......@@ -557,7 +556,15 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
}
FnKind::Closure => {}
}
}
pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
function_kind: FnKind<'v>,
function_declaration: &'v FnDecl,
function_body: &'v Block,
_span: Span) {
walk_fn_decl(visitor, function_declaration);
walk_fn_kind(visitor, function_kind);
visitor.visit_block(function_body)
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册