diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index abc35634d15f4..6f5f548aa7802 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -129,8 +129,8 @@ impl<'a> CheckAttrVisitor<'a> { } } -impl<'a> Visitor for CheckAttrVisitor<'a> { - fn visit_item(&mut self, item: &ast::Item) { +impl<'a> Visitor<'a> for CheckAttrVisitor<'a> { + fn visit_item(&mut self, item: &'a ast::Item) { let target = Target::from_item(item); for attr in &item.attrs { self.check_attribute(attr, target); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 615738277bf5c..74876eb59ee9a 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -143,14 +143,14 @@ impl<'a> LoweringContext<'a> { lctx: &'lcx mut LoweringContext<'interner>, } - impl<'lcx, 'interner> Visitor for ItemLowerer<'lcx, 'interner> { - fn visit_item(&mut self, item: &Item) { + impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> { + fn visit_item(&mut self, item: &'lcx Item) { let hir_item = self.lctx.lower_item(item); self.lctx.items.insert(item.id, hir_item); visit::walk_item(self, item); } - fn visit_impl_item(&mut self, item: &ImplItem) { + fn visit_impl_item(&mut self, item: &'lcx ImplItem) { let id = self.lctx.lower_impl_item_ref(item).id; let hir_item = self.lctx.lower_impl_item(item); self.lctx.impl_items.insert(id, hir_item); diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index 273094b735c3a..eb5a89f320e7b 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -135,8 +135,8 @@ impl<'a> DefCollector<'a> { } } -impl<'a> visit::Visitor for DefCollector<'a> { - fn visit_item(&mut self, i: &Item) { +impl<'a> visit::Visitor<'a> for DefCollector<'a> { + fn visit_item(&mut self, i: &'a Item) { debug!("visit_item: {:?}", i); // Pick the def data. This need not be unique, but the more @@ -211,7 +211,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { }); } - fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) { let def = self.create_def(foreign_item.id, DefPathData::ValueNs(foreign_item.ident.name.as_str())); @@ -220,7 +220,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { }); } - fn visit_generics(&mut self, generics: &Generics) { + fn visit_generics(&mut self, generics: &'a Generics) { for ty_param in generics.ty_params.iter() { self.create_def(ty_param.id, DefPathData::TypeParam(ty_param.ident.name.as_str())); } @@ -228,7 +228,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { visit::walk_generics(self, generics); } - fn visit_trait_item(&mut self, ti: &TraitItem) { + fn visit_trait_item(&mut self, ti: &'a TraitItem) { let def_data = match ti.node { TraitItemKind::Method(..) | TraitItemKind::Const(..) => DefPathData::ValueNs(ti.ident.name.as_str()), @@ -246,7 +246,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { }); } - fn visit_impl_item(&mut self, ii: &ImplItem) { + fn visit_impl_item(&mut self, ii: &'a ImplItem) { let def_data = match ii.node { ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.name.as_str()), @@ -264,7 +264,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { }); } - fn visit_pat(&mut self, pat: &Pat) { + fn visit_pat(&mut self, pat: &'a Pat) { let parent_def = self.parent_def; match pat.node { @@ -280,7 +280,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { self.parent_def = parent_def; } - fn visit_expr(&mut self, expr: &Expr) { + fn visit_expr(&mut self, expr: &'a Expr) { let parent_def = self.parent_def; match expr.node { @@ -297,7 +297,7 @@ impl<'a> visit::Visitor for DefCollector<'a> { self.parent_def = parent_def; } - fn visit_ty(&mut self, ty: &Ty) { + fn visit_ty(&mut self, ty: &'a Ty) { match ty.node { TyKind::Mac(..) => return self.visit_macro_invoc(ty.id, false), TyKind::Array(_, ref length) => self.visit_ast_const_integer(length), @@ -309,15 +309,15 @@ impl<'a> visit::Visitor for DefCollector<'a> { visit::walk_ty(self, ty); } - fn visit_lifetime_def(&mut self, def: &LifetimeDef) { + fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) { self.create_def(def.lifetime.id, DefPathData::LifetimeDef(def.lifetime.name.as_str())); } - fn visit_macro_def(&mut self, macro_def: &MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'a MacroDef) { self.create_def(macro_def.id, DefPathData::MacroDef(macro_def.ident.name.as_str())); } - fn visit_stmt(&mut self, stmt: &Stmt) { + fn visit_stmt(&mut self, stmt: &'a Stmt) { match stmt.node { StmtKind::Mac(..) => self.visit_macro_invoc(stmt.id, false), _ => visit::walk_stmt(self, stmt), diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 78d5067b273a5..02c1ece163497 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -262,4 +262,4 @@ impl LintPass for HardwiredLints { } } -impl LateLintPass for HardwiredLints {} +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {} diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index fba4f35074dbc..3ff2abac277b5 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -496,13 +496,13 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session, err } -pub trait LintContext: Sized { +pub trait LintContext<'tcx>: Sized { fn sess(&self) -> &Session; fn lints(&self) -> &LintStore; fn mut_lints(&mut self) -> &mut LintStore; fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)>; - fn enter_attrs(&mut self, attrs: &[ast::Attribute]); - fn exit_attrs(&mut self, attrs: &[ast::Attribute]); + fn enter_attrs(&mut self, attrs: &'tcx [ast::Attribute]); + fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]); /// Get the level of `lint` at the current position of the lint /// traversal. @@ -606,7 +606,7 @@ pub trait LintContext: Sized { /// current lint context, call the provided function, then reset the /// lints in effect to their previous state. fn with_lint_attrs(&mut self, - attrs: &[ast::Attribute], + attrs: &'tcx [ast::Attribute], f: F) where F: FnOnce(&mut Self), { @@ -729,7 +729,7 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> { } } -impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> { +impl<'a, 'tcx> LintContext<'tcx> for LateContext<'a, 'tcx> { /// Get the overall compiler `Session` object. fn sess(&self) -> &Session { &self.tcx.sess @@ -747,18 +747,18 @@ impl<'a, 'tcx> LintContext for LateContext<'a, 'tcx> { &mut self.level_stack } - fn enter_attrs(&mut self, attrs: &[ast::Attribute]) { + fn enter_attrs(&mut self, attrs: &'tcx [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]) { + fn exit_attrs(&mut self, attrs: &'tcx [ast::Attribute]) { debug!("late context: exit_attrs({:?})", attrs); run_lints!(self, exit_lint_attrs, late_passes, attrs); } } -impl<'a> LintContext for EarlyContext<'a> { +impl<'a> LintContext<'a> for EarlyContext<'a> { /// Get the overall compiler `Session` object. fn sess(&self) -> &Session { &self.sess @@ -776,12 +776,12 @@ impl<'a> LintContext for EarlyContext<'a> { &mut self.level_stack } - fn enter_attrs(&mut self, attrs: &[ast::Attribute]) { + fn enter_attrs(&mut self, attrs: &'a [ast::Attribute]) { debug!("early context: enter_attrs({:?})", attrs); run_lints!(self, enter_lint_attrs, early_passes, attrs); } - fn exit_attrs(&mut self, attrs: &[ast::Attribute]) { + fn exit_attrs(&mut self, attrs: &'a [ast::Attribute]) { debug!("early context: exit_attrs({:?})", attrs); run_lints!(self, exit_lint_attrs, early_passes, attrs); } @@ -949,14 +949,14 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { hir_visit::walk_path(self, p); } - fn visit_attribute(&mut self, attr: &ast::Attribute) { + fn visit_attribute(&mut self, attr: &'tcx ast::Attribute) { check_lint_name_attribute(self, attr); run_lints!(self, check_attribute, late_passes, attr); } } -impl<'a> ast_visit::Visitor for EarlyContext<'a> { - fn visit_item(&mut self, it: &ast::Item) { +impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { + fn visit_item(&mut self, it: &'a ast::Item) { self.with_lint_attrs(&it.attrs, |cx| { run_lints!(cx, check_item, early_passes, it); ast_visit::walk_item(cx, it); @@ -964,7 +964,7 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { }) } - fn visit_foreign_item(&mut self, it: &ast::ForeignItem) { + fn visit_foreign_item(&mut self, it: &'a ast::ForeignItem) { self.with_lint_attrs(&it.attrs, |cx| { run_lints!(cx, check_foreign_item, early_passes, it); ast_visit::walk_foreign_item(cx, it); @@ -972,24 +972,24 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { }) } - fn visit_pat(&mut self, p: &ast::Pat) { + fn visit_pat(&mut self, p: &'a ast::Pat) { run_lints!(self, check_pat, early_passes, p); ast_visit::walk_pat(self, p); } - fn visit_expr(&mut self, e: &ast::Expr) { + fn visit_expr(&mut self, e: &'a ast::Expr) { self.with_lint_attrs(&e.attrs, |cx| { run_lints!(cx, check_expr, early_passes, e); ast_visit::walk_expr(cx, e); }) } - fn visit_stmt(&mut self, s: &ast::Stmt) { + fn visit_stmt(&mut self, s: &'a ast::Stmt) { run_lints!(self, check_stmt, early_passes, s); ast_visit::walk_stmt(self, s); } - fn visit_fn(&mut self, fk: ast_visit::FnKind, decl: &ast::FnDecl, + fn visit_fn(&mut self, fk: ast_visit::FnKind<'a>, decl: &'a ast::FnDecl, span: Span, id: ast::NodeId) { run_lints!(self, check_fn, early_passes, fk, decl, span, id); ast_visit::walk_fn(self, fk, decl, span); @@ -997,9 +997,9 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { } fn visit_variant_data(&mut self, - s: &ast::VariantData, + s: &'a ast::VariantData, ident: ast::Ident, - g: &ast::Generics, + g: &'a ast::Generics, item_id: ast::NodeId, _: Span) { run_lints!(self, check_struct_def, early_passes, s, ident, g, item_id); @@ -1007,14 +1007,14 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { run_lints!(self, check_struct_def_post, early_passes, s, ident, g, item_id); } - fn visit_struct_field(&mut self, s: &ast::StructField) { + fn visit_struct_field(&mut self, s: &'a ast::StructField) { self.with_lint_attrs(&s.attrs, |cx| { run_lints!(cx, check_struct_field, early_passes, s); ast_visit::walk_struct_field(cx, s); }) } - fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics, item_id: ast::NodeId) { + fn visit_variant(&mut self, v: &'a ast::Variant, g: &'a ast::Generics, item_id: ast::NodeId) { self.with_lint_attrs(&v.node.attrs, |cx| { run_lints!(cx, check_variant, early_passes, v, g); ast_visit::walk_variant(cx, v, g, item_id); @@ -1022,7 +1022,7 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { }) } - fn visit_ty(&mut self, t: &ast::Ty) { + fn visit_ty(&mut self, t: &'a ast::Ty) { run_lints!(self, check_ty, early_passes, t); ast_visit::walk_ty(self, t); } @@ -1031,40 +1031,40 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { run_lints!(self, check_ident, early_passes, sp, id); } - fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) { + fn visit_mod(&mut self, m: &'a ast::Mod, s: Span, n: ast::NodeId) { run_lints!(self, check_mod, early_passes, m, s, n); ast_visit::walk_mod(self, m); run_lints!(self, check_mod_post, early_passes, m, s, n); } - fn visit_local(&mut self, l: &ast::Local) { + fn visit_local(&mut self, l: &'a ast::Local) { self.with_lint_attrs(&l.attrs, |cx| { run_lints!(cx, check_local, early_passes, l); ast_visit::walk_local(cx, l); }) } - fn visit_block(&mut self, b: &ast::Block) { + fn visit_block(&mut self, b: &'a ast::Block) { run_lints!(self, check_block, early_passes, b); ast_visit::walk_block(self, b); run_lints!(self, check_block_post, early_passes, b); } - fn visit_arm(&mut self, a: &ast::Arm) { + fn visit_arm(&mut self, a: &'a ast::Arm) { run_lints!(self, check_arm, early_passes, a); ast_visit::walk_arm(self, a); } - fn visit_expr_post(&mut self, e: &ast::Expr) { + fn visit_expr_post(&mut self, e: &'a ast::Expr) { run_lints!(self, check_expr_post, early_passes, e); } - fn visit_generics(&mut self, g: &ast::Generics) { + fn visit_generics(&mut self, g: &'a ast::Generics) { run_lints!(self, check_generics, early_passes, g); ast_visit::walk_generics(self, g); } - fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) { + fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) { self.with_lint_attrs(&trait_item.attrs, |cx| { run_lints!(cx, check_trait_item, early_passes, trait_item); ast_visit::walk_trait_item(cx, trait_item); @@ -1072,7 +1072,7 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { }); } - fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) { + fn visit_impl_item(&mut self, impl_item: &'a ast::ImplItem) { self.with_lint_attrs(&impl_item.attrs, |cx| { run_lints!(cx, check_impl_item, early_passes, impl_item); ast_visit::walk_impl_item(cx, impl_item); @@ -1080,25 +1080,25 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> { }); } - fn visit_lifetime(&mut self, lt: &ast::Lifetime) { + fn visit_lifetime(&mut self, lt: &'a ast::Lifetime) { run_lints!(self, check_lifetime, early_passes, lt); } - fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) { + fn visit_lifetime_def(&mut self, lt: &'a ast::LifetimeDef) { run_lints!(self, check_lifetime_def, early_passes, lt); } - fn visit_path(&mut self, p: &ast::Path, id: ast::NodeId) { + fn visit_path(&mut self, p: &'a ast::Path, id: ast::NodeId) { run_lints!(self, check_path, early_passes, p, id); ast_visit::walk_path(self, p); } - fn visit_path_list_item(&mut self, prefix: &ast::Path, item: &ast::PathListItem) { + fn visit_path_list_item(&mut self, prefix: &'a ast::Path, item: &'a ast::PathListItem) { run_lints!(self, check_path_list_item, early_passes, item); ast_visit::walk_path_list_item(self, prefix, item); } - fn visit_attribute(&mut self, attr: &ast::Attribute) { + fn visit_attribute(&mut self, attr: &'a ast::Attribute) { run_lints!(self, check_attribute, early_passes, attr); } } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 4e06e0abf0148..ccf53f01cd532 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -129,53 +129,85 @@ pub trait LintPass { // // FIXME: eliminate the duplication with `Visitor`. But this also // contains a few lint-specific methods with no equivalent in `Visitor`. -pub trait LateLintPass: LintPass { +pub trait LateLintPass<'a, 'tcx>: LintPass { fn check_name(&mut self, _: &LateContext, _: Span, _: ast::Name) { } - fn check_crate(&mut self, _: &LateContext, _: &hir::Crate) { } - fn check_crate_post(&mut self, _: &LateContext, _: &hir::Crate) { } - fn check_mod(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { } - fn check_mod_post(&mut self, _: &LateContext, _: &hir::Mod, _: Span, _: ast::NodeId) { } - fn check_foreign_item(&mut self, _: &LateContext, _: &hir::ForeignItem) { } - fn check_foreign_item_post(&mut self, _: &LateContext, _: &hir::ForeignItem) { } - fn check_item(&mut self, _: &LateContext, _: &hir::Item) { } - fn check_item_post(&mut self, _: &LateContext, _: &hir::Item) { } - fn check_local(&mut self, _: &LateContext, _: &hir::Local) { } - fn check_block(&mut self, _: &LateContext, _: &hir::Block) { } - fn check_block_post(&mut self, _: &LateContext, _: &hir::Block) { } - fn check_stmt(&mut self, _: &LateContext, _: &hir::Stmt) { } - fn check_arm(&mut self, _: &LateContext, _: &hir::Arm) { } - fn check_pat(&mut self, _: &LateContext, _: &hir::Pat) { } - fn check_decl(&mut self, _: &LateContext, _: &hir::Decl) { } - fn check_expr(&mut self, _: &LateContext, _: &hir::Expr) { } - fn check_expr_post(&mut self, _: &LateContext, _: &hir::Expr) { } - fn check_ty(&mut self, _: &LateContext, _: &hir::Ty) { } - fn check_generics(&mut self, _: &LateContext, _: &hir::Generics) { } - fn check_fn(&mut self, _: &LateContext, - _: FnKind, _: &hir::FnDecl, _: &hir::Expr, _: Span, _: ast::NodeId) { } - fn check_fn_post(&mut self, _: &LateContext, - _: FnKind, _: &hir::FnDecl, _: &hir::Expr, _: Span, _: ast::NodeId) { } - fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { } - fn check_trait_item_post(&mut self, _: &LateContext, _: &hir::TraitItem) { } - fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { } - fn check_impl_item_post(&mut self, _: &LateContext, _: &hir::ImplItem) { } - fn check_struct_def(&mut self, _: &LateContext, - _: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { } - fn check_struct_def_post(&mut self, _: &LateContext, - _: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { } - 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_lifetime(&mut self, _: &LateContext, _: &hir::Lifetime) { } - fn check_lifetime_def(&mut self, _: &LateContext, _: &hir::LifetimeDef) { } - fn check_path(&mut self, _: &LateContext, _: &hir::Path, _: ast::NodeId) { } - fn check_attribute(&mut self, _: &LateContext, _: &ast::Attribute) { } + fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { } + fn check_crate_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Crate) { } + fn check_mod(&mut self, + _: &LateContext<'a, 'tcx>, + _: &'tcx hir::Mod, + _: Span, + _: ast::NodeId) { } + fn check_mod_post(&mut self, + _: &LateContext<'a, 'tcx>, + _: &'tcx hir::Mod, + _: Span, + _: ast::NodeId) { } + fn check_foreign_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ForeignItem) { } + fn check_foreign_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ForeignItem) { } + fn check_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Item) { } + fn check_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Item) { } + fn check_local(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Local) { } + fn check_block(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Block) { } + fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Block) { } + fn check_stmt(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Stmt) { } + fn check_arm(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Arm) { } + fn check_pat(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Pat) { } + fn check_decl(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Decl) { } + fn check_expr(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Expr) { } + fn check_expr_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Expr) { } + fn check_ty(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Ty) { } + fn check_generics(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Generics) { } + fn check_fn(&mut self, + _: &LateContext<'a, 'tcx>, + _: FnKind<'tcx>, + _: &'tcx hir::FnDecl, + _: &'tcx hir::Expr, + _: Span, + _: ast::NodeId) { } + fn check_fn_post(&mut self, + _: &LateContext<'a, 'tcx>, + _: FnKind<'tcx>, + _: &'tcx hir::FnDecl, + _: &'tcx hir::Expr, + _: Span, + _: ast::NodeId) { } + fn check_trait_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::TraitItem) { } + fn check_trait_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::TraitItem) { } + fn check_impl_item(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ImplItem) { } + fn check_impl_item_post(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::ImplItem) { } + fn check_struct_def(&mut self, + _: &LateContext<'a, 'tcx>, + _: &'tcx hir::VariantData, + _: ast::Name, + _: &'tcx hir::Generics, + _: ast::NodeId) { } + fn check_struct_def_post(&mut self, + _: &LateContext<'a, 'tcx>, + _: &'tcx hir::VariantData, + _: ast::Name, + _: &'tcx hir::Generics, + _: ast::NodeId) { } + fn check_struct_field(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::StructField) { } + fn check_variant(&mut self, + _: &LateContext<'a, 'tcx>, + _: &'tcx hir::Variant, + _: &'tcx hir::Generics) { } + fn check_variant_post(&mut self, + _: &LateContext<'a, 'tcx>, + _: &'tcx hir::Variant, + _: &'tcx hir::Generics) { } + fn check_lifetime(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Lifetime) { } + fn check_lifetime_def(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::LifetimeDef) { } + fn check_path(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Path, _: ast::NodeId) { } + fn check_attribute(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx ast::Attribute) { } /// Called when entering a syntax node that can have lint attributes such /// as `#[allow(...)]`. Called with *all* the attributes of that node. - fn enter_lint_attrs(&mut self, _: &LateContext, _: &[ast::Attribute]) { } + fn enter_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx [ast::Attribute]) { } /// Counterpart to `enter_lint_attrs`. - fn exit_lint_attrs(&mut self, _: &LateContext, _: &[ast::Attribute]) { } + fn exit_lint_attrs(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx [ast::Attribute]) { } } pub trait EarlyLintPass: LintPass { @@ -229,7 +261,7 @@ pub trait EarlyLintPass: LintPass { /// A lint pass boxed up as a trait object. pub type EarlyLintPassObject = Box; -pub type LateLintPassObject = Box; +pub type LateLintPassObject = Box LateLintPass<'a, 'tcx> + 'static>; /// Identifies a lint known to the compiler. #[derive(Clone, Copy, Debug)] diff --git a/src/librustc_lint/bad_style.rs b/src/librustc_lint/bad_style.rs index 7c3ea656124bc..2aa74407afc5b 100644 --- a/src/librustc_lint/bad_style.rs +++ b/src/librustc_lint/bad_style.rs @@ -99,7 +99,7 @@ impl LintPass for NonCamelCaseTypes { } } -impl LateLintPass for NonCamelCaseTypes { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonCamelCaseTypes { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { let extern_repr_count = it.attrs .iter() @@ -226,7 +226,7 @@ impl LintPass for NonSnakeCase { } } -impl LateLintPass for NonSnakeCase { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { fn check_crate(&mut self, cx: &LateContext, cr: &hir::Crate) { let attr_crate_name = cr.attrs .iter() @@ -348,7 +348,7 @@ impl LintPass for NonUpperCaseGlobals { } } -impl LateLintPass for NonUpperCaseGlobals { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonUpperCaseGlobals { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { hir::ItemStatic(..) => { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index f14fa7d4fdc23..744b08a2a8900 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -69,7 +69,7 @@ impl LintPass for WhileTrue { } } -impl LateLintPass for WhileTrue { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for WhileTrue { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { if let hir::ExprWhile(ref cond, ..) = e.node { if let hir::ExprLit(ref lit) = cond.node { @@ -93,7 +93,7 @@ declare_lint! { pub struct BoxPointers; impl BoxPointers { - fn check_heap_type<'a, 'tcx>(&self, cx: &LateContext<'a, 'tcx>, span: Span, ty: Ty<'tcx>) { + fn check_heap_type<'a, 'tcx>(&self, cx: &LateContext, span: Span, ty: Ty) { for leaf_ty in ty.walk() { if let ty::TyBox(_) = leaf_ty.sty { let m = format!("type uses owned (Box type) pointers: {}", ty); @@ -109,7 +109,7 @@ impl LintPass for BoxPointers { } } -impl LateLintPass for BoxPointers { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxPointers { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { hir::ItemFn(..) | @@ -158,7 +158,7 @@ impl LintPass for NonShorthandFieldPatterns { } } -impl LateLintPass for NonShorthandFieldPatterns { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) { if let PatKind::Struct(_, ref field_pats, _) = pat.node { for fieldpat in field_pats { @@ -194,7 +194,7 @@ impl LintPass for UnsafeCode { } } -impl LateLintPass for UnsafeCode { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { if let hir::ExprBlock(ref blk) = e.node { // Don't warn about generated blocks, that'll just pollute the output. @@ -220,7 +220,7 @@ impl LateLintPass for UnsafeCode { fn check_fn(&mut self, cx: &LateContext, - fk: FnKind, + fk: FnKind<'tcx>, _: &hir::FnDecl, _: &hir::Expr, span: Span, @@ -327,7 +327,7 @@ impl LintPass for MissingDoc { } } -impl LateLintPass for MissingDoc { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { fn enter_lint_attrs(&mut self, _: &LateContext, attrs: &[ast::Attribute]) { let doc_hidden = self.doc_hidden() || attrs.iter().any(|attr| { @@ -340,7 +340,7 @@ impl LateLintPass for MissingDoc { self.doc_hidden_stack.push(doc_hidden); } - fn exit_lint_attrs(&mut self, _: &LateContext, _: &[ast::Attribute]) { + fn exit_lint_attrs(&mut self, _: &LateContext, _attrs: &[ast::Attribute]) { self.doc_hidden_stack.pop().expect("empty doc_hidden_stack"); } @@ -494,7 +494,7 @@ impl LintPass for MissingCopyImplementations { } } -impl LateLintPass for MissingCopyImplementations { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations { fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { if !cx.access_levels.is_reachable(item.id) { return; @@ -563,7 +563,7 @@ impl LintPass for MissingDebugImplementations { } } -impl LateLintPass for MissingDebugImplementations { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations { fn check_item(&mut self, cx: &LateContext, item: &hir::Item) { if !cx.access_levels.is_reachable(item.id) { return; @@ -669,7 +669,7 @@ impl LintPass for UnconditionalRecursion { } } -impl LateLintPass for UnconditionalRecursion { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion { fn check_fn(&mut self, cx: &LateContext, fn_kind: FnKind, @@ -932,7 +932,7 @@ impl LintPass for PluginAsLibrary { } } -impl LateLintPass for PluginAsLibrary { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { if cx.sess().plugin_registrar_fn.get().is_some() { // We're compiling a plugin; it's fine to link other plugins. @@ -998,7 +998,7 @@ impl LintPass for InvalidNoMangleItems { } } -impl LateLintPass for InvalidNoMangleItems { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidNoMangleItems { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match it.node { hir::ItemFn(.., ref generics, _) => { @@ -1052,7 +1052,7 @@ impl LintPass for MutableTransmutes { } } -impl LateLintPass for MutableTransmutes { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes { fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) { use syntax::abi::Abi::RustIntrinsic; @@ -1120,7 +1120,7 @@ impl LintPass for UnstableFeatures { } } -impl LateLintPass for UnstableFeatures { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures { fn check_attribute(&mut self, ctx: &LateContext, attr: &ast::Attribute) { if attr.meta().check_name("feature") { if let Some(items) = attr.meta().meta_item_list() { @@ -1147,7 +1147,7 @@ impl LintPass for UnionsWithDropFields { } } -impl LateLintPass for UnionsWithDropFields { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields { fn check_item(&mut self, ctx: &LateContext, item: &hir::Item) { if let hir::ItemUnion(ref vdata, _) = item.node { let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id); diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index bba31c8237d18..8470f063f47d7 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -103,7 +103,7 @@ impl LintPass for TypeLimits { } } -impl LateLintPass for TypeLimits { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { match e.node { hir::ExprUnary(hir::UnNeg, ref expr) => { @@ -706,7 +706,7 @@ impl LintPass for ImproperCTypes { } } -impl LateLintPass for ImproperCTypes { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { let mut vis = ImproperCTypesVisitor { cx: cx }; if let hir::ItemForeignMod(ref nmod) = it.node { @@ -734,7 +734,7 @@ impl LintPass for VariantSizeDifferences { } } -impl LateLintPass for VariantSizeDifferences { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { if let hir::ItemEnum(ref enum_definition, ref gens) = it.node { if gens.ty_params.is_empty() { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 873c141065ec3..429bfb8e3d606 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -77,7 +77,7 @@ impl LintPass for UnusedMut { } } -impl LateLintPass for UnusedMut { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedMut { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { if let hir::ExprMatch(_, ref arms, _) = e.node { for a in arms { @@ -128,7 +128,7 @@ impl LintPass for UnusedResults { } } -impl LateLintPass for UnusedResults { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { let expr = match s.node { hir::StmtSemi(ref expr, _) => &**expr, @@ -187,7 +187,7 @@ impl LintPass for UnusedUnsafe { } } -impl LateLintPass for UnusedUnsafe { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedUnsafe { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { if let hir::ExprBlock(ref blk) = e.node { // Don't warn about generated blocks, that'll just pollute the output. @@ -214,7 +214,7 @@ impl LintPass for PathStatements { } } -impl LateLintPass for PathStatements { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements { fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) { if let hir::StmtSemi(ref expr, _) = s.node { if let hir::ExprPath(_) = expr.node { @@ -239,7 +239,7 @@ impl LintPass for UnusedAttributes { } } -impl LateLintPass for UnusedAttributes { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAttributes { fn check_attribute(&mut self, cx: &LateContext, attr: &ast::Attribute) { debug!("checking attribute: {:?}", attr); @@ -433,7 +433,7 @@ impl LintPass for UnusedAllocation { } } -impl LateLintPass for UnusedAllocation { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedAllocation { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { match e.node { hir::ExprBox(_) => {} diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index fa07006aa63e1..2d0f0864752ab 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -101,8 +101,8 @@ impl<'a> AstValidator<'a> { } } -impl<'a> Visitor for AstValidator<'a> { - fn visit_lifetime(&mut self, lt: &Lifetime) { +impl<'a> Visitor<'a> for AstValidator<'a> { + fn visit_lifetime(&mut self, lt: &'a Lifetime) { if lt.name == "'_" { self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE, lt.id, @@ -113,7 +113,7 @@ impl<'a> Visitor for AstValidator<'a> { visit::walk_lifetime(self, lt) } - fn visit_expr(&mut self, expr: &Expr) { + fn visit_expr(&mut self, expr: &'a Expr) { match expr.node { ExprKind::While(.., Some(ident)) | ExprKind::Loop(_, Some(ident)) | @@ -129,7 +129,7 @@ impl<'a> Visitor for AstValidator<'a> { visit::walk_expr(self, expr) } - fn visit_ty(&mut self, ty: &Ty) { + fn visit_ty(&mut self, ty: &'a Ty) { match ty.node { TyKind::BareFn(ref bfty) => { self.check_decl_no_pat(&bfty.decl, |span, _| { @@ -153,7 +153,7 @@ impl<'a> Visitor for AstValidator<'a> { visit::walk_ty(self, ty) } - fn visit_path(&mut self, path: &Path, id: NodeId) { + fn visit_path(&mut self, path: &'a Path, id: NodeId) { if path.global && path.segments.len() > 0 { let ident = path.segments[0].identifier; if token::Ident(ident).is_path_segment_keyword() { @@ -167,7 +167,7 @@ impl<'a> Visitor for AstValidator<'a> { visit::walk_path(self, path) } - fn visit_item(&mut self, item: &Item) { + fn visit_item(&mut self, item: &'a Item) { match item.node { ItemKind::Use(ref view_path) => { let path = view_path.node.path(); @@ -249,7 +249,7 @@ impl<'a> Visitor for AstValidator<'a> { visit::walk_item(self, item) } - fn visit_foreign_item(&mut self, fi: &ForeignItem) { + fn visit_foreign_item(&mut self, fi: &'a ForeignItem) { match fi.node { ForeignItemKind::Fn(ref decl, _) => { self.check_decl_no_pat(decl, |span, is_recent| { @@ -272,7 +272,7 @@ impl<'a> Visitor for AstValidator<'a> { visit::walk_foreign_item(self, fi) } - fn visit_vis(&mut self, vis: &Visibility) { + fn visit_vis(&mut self, vis: &'a Visibility) { match *vis { Visibility::Restricted { ref path, .. } => { if !path.segments.iter().all(|segment| segment.parameters.is_empty()) { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index b785801398895..f7e026866e2df 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -48,7 +48,7 @@ pub fn print_hir_stats(krate: &hir::Crate) { collector.print("HIR STATS"); } -pub fn print_ast_stats(krate: &ast::Crate, title: &str) { +pub fn print_ast_stats<'v>(krate: &'v ast::Crate, title: &str) { let mut collector = StatCollector { krate: None, data: FxHashMap(), @@ -245,133 +245,133 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } } -impl<'v> ast_visit::Visitor for StatCollector<'v> { +impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { - fn visit_mod(&mut self, m: &ast::Mod, _s: Span, _n: NodeId) { + fn visit_mod(&mut self, m: &'v ast::Mod, _s: Span, _n: NodeId) { self.record("Mod", Id::None, m); ast_visit::walk_mod(self, m) } - fn visit_foreign_item(&mut self, i: &ast::ForeignItem) { + fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) { self.record("ForeignItem", Id::None, i); ast_visit::walk_foreign_item(self, i) } - fn visit_item(&mut self, i: &ast::Item) { + fn visit_item(&mut self, i: &'v ast::Item) { self.record("Item", Id::None, i); ast_visit::walk_item(self, i) } - fn visit_local(&mut self, l: &ast::Local) { + fn visit_local(&mut self, l: &'v ast::Local) { self.record("Local", Id::None, l); ast_visit::walk_local(self, l) } - fn visit_block(&mut self, b: &ast::Block) { + fn visit_block(&mut self, b: &'v ast::Block) { self.record("Block", Id::None, b); ast_visit::walk_block(self, b) } - fn visit_stmt(&mut self, s: &ast::Stmt) { + fn visit_stmt(&mut self, s: &'v ast::Stmt) { self.record("Stmt", Id::None, s); ast_visit::walk_stmt(self, s) } - fn visit_arm(&mut self, a: &ast::Arm) { + fn visit_arm(&mut self, a: &'v ast::Arm) { self.record("Arm", Id::None, a); ast_visit::walk_arm(self, a) } - fn visit_pat(&mut self, p: &ast::Pat) { + fn visit_pat(&mut self, p: &'v ast::Pat) { self.record("Pat", Id::None, p); ast_visit::walk_pat(self, p) } - fn visit_expr(&mut self, ex: &ast::Expr) { + fn visit_expr(&mut self, ex: &'v ast::Expr) { self.record("Expr", Id::None, ex); ast_visit::walk_expr(self, ex) } - fn visit_ty(&mut self, t: &ast::Ty) { + fn visit_ty(&mut self, t: &'v ast::Ty) { self.record("Ty", Id::None, t); ast_visit::walk_ty(self, t) } fn visit_fn(&mut self, - fk: ast_visit::FnKind, - fd: &ast::FnDecl, + fk: ast_visit::FnKind<'v>, + fd: &'v ast::FnDecl, s: Span, _: NodeId) { self.record("FnDecl", Id::None, fd); ast_visit::walk_fn(self, fk, fd, s) } - fn visit_trait_item(&mut self, ti: &ast::TraitItem) { + fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) { self.record("TraitItem", Id::None, ti); ast_visit::walk_trait_item(self, ti) } - fn visit_impl_item(&mut self, ii: &ast::ImplItem) { + fn visit_impl_item(&mut self, ii: &'v ast::ImplItem) { self.record("ImplItem", Id::None, ii); ast_visit::walk_impl_item(self, ii) } - fn visit_ty_param_bound(&mut self, bounds: &ast::TyParamBound) { + fn visit_ty_param_bound(&mut self, bounds: &'v ast::TyParamBound) { self.record("TyParamBound", Id::None, bounds); ast_visit::walk_ty_param_bound(self, bounds) } - fn visit_struct_field(&mut self, s: &ast::StructField) { + fn visit_struct_field(&mut self, s: &'v ast::StructField) { self.record("StructField", Id::None, s); ast_visit::walk_struct_field(self, s) } fn visit_variant(&mut self, - v: &ast::Variant, - g: &ast::Generics, + v: &'v ast::Variant, + g: &'v ast::Generics, item_id: NodeId) { self.record("Variant", Id::None, v); ast_visit::walk_variant(self, v, g, item_id) } - fn visit_lifetime(&mut self, lifetime: &ast::Lifetime) { + fn visit_lifetime(&mut self, lifetime: &'v ast::Lifetime) { self.record("Lifetime", Id::None, lifetime); ast_visit::walk_lifetime(self, lifetime) } - fn visit_lifetime_def(&mut self, lifetime: &ast::LifetimeDef) { + fn visit_lifetime_def(&mut self, lifetime: &'v ast::LifetimeDef) { self.record("LifetimeDef", Id::None, lifetime); ast_visit::walk_lifetime_def(self, lifetime) } - fn visit_mac(&mut self, mac: &ast::Mac) { + fn visit_mac(&mut self, mac: &'v ast::Mac) { self.record("Mac", Id::None, mac); } fn visit_path_list_item(&mut self, - prefix: &ast::Path, - item: &ast::PathListItem) { + prefix: &'v ast::Path, + item: &'v ast::PathListItem) { self.record("PathListItem", Id::None, item); ast_visit::walk_path_list_item(self, prefix, item) } fn visit_path_segment(&mut self, path_span: Span, - path_segment: &ast::PathSegment) { + path_segment: &'v ast::PathSegment) { self.record("PathSegment", Id::None, path_segment); ast_visit::walk_path_segment(self, path_span, path_segment) } - fn visit_assoc_type_binding(&mut self, type_binding: &ast::TypeBinding) { + fn visit_assoc_type_binding(&mut self, type_binding: &'v ast::TypeBinding) { self.record("TypeBinding", Id::None, type_binding); ast_visit::walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, attr: &ast::Attribute) { + fn visit_attribute(&mut self, attr: &'v ast::Attribute) { self.record("Attribute", Id::None, attr); } - fn visit_macro_def(&mut self, macro_def: &ast::MacroDef) { + fn visit_macro_def(&mut self, macro_def: &'v ast::MacroDef) { self.record("MacroDef", Id::None, macro_def); ast_visit::walk_macro_def(self, macro_def) } diff --git a/src/librustc_passes/no_asm.rs b/src/librustc_passes/no_asm.rs index af3065d64e8db..4dbf57a99bcbe 100644 --- a/src/librustc_passes/no_asm.rs +++ b/src/librustc_passes/no_asm.rs @@ -31,8 +31,8 @@ struct CheckNoAsm<'a> { sess: &'a Session, } -impl<'a> Visitor for CheckNoAsm<'a> { - fn visit_expr(&mut self, e: &ast::Expr) { +impl<'a> Visitor<'a> for CheckNoAsm<'a> { + fn visit_expr(&mut self, e: &'a ast::Expr) { match e.node { ast::ExprKind::InlineAsm(_) => { span_err!(self.sess, diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 7bcc543023e78..25a37931ba31f 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -678,7 +678,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { macro_rules! method { ($visit:ident: $ty:ty, $invoc:path, $walk:ident) => { - fn $visit(&mut self, node: &$ty) { + fn $visit(&mut self, node: &'a $ty) { if let $invoc(..) = node.node { self.visit_invoc(node.id); } else { @@ -688,13 +688,13 @@ macro_rules! method { } } -impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> { +impl<'a, 'b> Visitor<'a> for BuildReducedGraphVisitor<'a, 'b> { method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item); method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr); method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat); method!(visit_ty: ast::Ty, ast::TyKind::Mac, walk_ty); - fn visit_item(&mut self, item: &Item) { + fn visit_item(&mut self, item: &'a Item) { let macro_use = match item.node { ItemKind::Mac(..) if item.id == ast::DUMMY_NODE_ID => return, // Scope placeholder ItemKind::Mac(..) => { @@ -713,7 +713,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> { } } - fn visit_stmt(&mut self, stmt: &ast::Stmt) { + fn visit_stmt(&mut self, stmt: &'a ast::Stmt) { if let ast::StmtKind::Mac(..) = stmt.node { self.legacy_scope = LegacyScope::Expansion(self.visit_invoc(stmt.id)); } else { @@ -721,12 +721,12 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> { } } - fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) { self.resolver.build_reduced_graph_for_foreign_item(foreign_item, self.expansion); visit::walk_foreign_item(self, foreign_item); } - fn visit_block(&mut self, block: &Block) { + fn visit_block(&mut self, block: &'a Block) { let (parent, legacy_scope) = (self.resolver.current_module, self.legacy_scope); self.resolver.build_reduced_graph_for_block(block); visit::walk_block(self, block); @@ -734,7 +734,7 @@ impl<'a, 'b> Visitor for BuildReducedGraphVisitor<'a, 'b> { self.legacy_scope = legacy_scope; } - fn visit_trait_item(&mut self, item: &TraitItem) { + fn visit_trait_item(&mut self, item: &'a TraitItem) { let parent = self.resolver.current_module; let def_id = parent.def_id().unwrap(); diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 492c5e695bbbb..19aa5f78fd571 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -74,8 +74,8 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> { } } -impl<'a, 'b> Visitor for UnusedImportCheckVisitor<'a, 'b> { - fn visit_item(&mut self, item: &ast::Item) { +impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> { + fn visit_item(&mut self, item: &'a ast::Item) { visit::walk_item(self, item); // Ignore is_public import statements because there's no way to be sure // whether they're used or not. Also ignore imports with a dummy span diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index d5297a5a47dae..f7aaf2475f65e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -557,26 +557,28 @@ impl ::std::ops::IndexMut for PerNS { } } -impl<'a> Visitor for Resolver<'a> { - fn visit_item(&mut self, item: &Item) { +impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { + fn visit_item(&mut self, item: &'tcx Item) { self.resolve_item(item); } - fn visit_arm(&mut self, arm: &Arm) { + fn visit_arm(&mut self, arm: &'tcx Arm) { self.resolve_arm(arm); } - fn visit_block(&mut self, block: &Block) { + fn visit_block(&mut self, block: &'tcx Block) { self.resolve_block(block); } - fn visit_expr(&mut self, expr: &Expr) { + fn visit_expr(&mut self, expr: &'tcx Expr) { self.resolve_expr(expr, None); } - fn visit_local(&mut self, local: &Local) { + fn visit_local(&mut self, local: &'tcx Local) { self.resolve_local(local); } - fn visit_ty(&mut self, ty: &Ty) { + fn visit_ty(&mut self, ty: &'tcx Ty) { self.resolve_type(ty); } - fn visit_poly_trait_ref(&mut self, tref: &ast::PolyTraitRef, m: &ast::TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, + tref: &'tcx ast::PolyTraitRef, + m: &'tcx ast::TraitBoundModifier) { let ast::Path { ref segments, span, global } = tref.trait_ref.path; let path: Vec<_> = segments.iter().map(|seg| seg.identifier).collect(); let def = self.resolve_trait_reference(&path, global, None, span); @@ -584,8 +586,8 @@ impl<'a> Visitor for Resolver<'a> { visit::walk_poly_trait_ref(self, tref, m); } fn visit_variant(&mut self, - variant: &ast::Variant, - generics: &Generics, + variant: &'tcx ast::Variant, + generics: &'tcx Generics, item_id: ast::NodeId) { if let Some(ref dis_expr) = variant.node.disr_expr { // resolve the discriminator expr as a constant @@ -601,7 +603,7 @@ impl<'a> Visitor for Resolver<'a> { item_id, variant.span); } - fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) { + fn visit_foreign_item(&mut self, foreign_item: &'tcx ForeignItem) { let type_parameters = match foreign_item.node { ForeignItemKind::Fn(_, ref generics) => { HasTypeParameters(generics, ItemRibKind) @@ -613,8 +615,8 @@ impl<'a> Visitor for Resolver<'a> { }); } fn visit_fn(&mut self, - function_kind: FnKind, - declaration: &FnDecl, + function_kind: FnKind<'tcx>, + declaration: &'tcx FnDecl, _: Span, node_id: NodeId) { let rib_kind = match function_kind { diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 4cd28e0a46daf..ec368c6bc1fa2 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -345,7 +345,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } } - fn process_formals(&mut self, formals: &Vec, qualname: &str) { + fn process_formals(&mut self, formals: &'l [ast::Arg], qualname: &str) { for arg in formals { self.visit_pat(&arg.pat); let mut collector = PathCollector::new(); @@ -379,12 +379,12 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } fn process_method(&mut self, - sig: &ast::MethodSig, - body: Option<&ast::Block>, + sig: &'l ast::MethodSig, + body: Option<&'l ast::Block>, id: ast::NodeId, name: ast::Name, vis: Visibility, - attrs: &[Attribute], + attrs: &'l [Attribute], span: Span) { debug!("process_method: {}:{}", id, name); @@ -465,7 +465,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } } - fn process_trait_ref(&mut self, trait_ref: &ast::TraitRef) { + fn process_trait_ref(&mut self, trait_ref: &'l ast::TraitRef) { let trait_ref_data = self.save_ctxt.get_trait_ref_data(trait_ref, self.cur_scope); if let Some(trait_ref_data) = trait_ref_data { if !self.span.filter_generated(Some(trait_ref_data.span), trait_ref.path.span) { @@ -488,7 +488,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { // Dump generic params bindings, then visit_generics fn process_generic_params(&mut self, - generics: &ast::Generics, + generics: &'l ast::Generics, full_span: Span, prefix: &str, id: NodeId) { @@ -522,10 +522,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } fn process_fn(&mut self, - item: &ast::Item, - decl: &ast::FnDecl, - ty_params: &ast::Generics, - body: &ast::Block) { + item: &'l ast::Item, + decl: &'l ast::FnDecl, + ty_params: &'l ast::Generics, + body: &'l ast::Block) { if let Some(fn_data) = self.save_ctxt.get_item_data(item) { down_cast_data!(fn_data, FunctionData, item.span); if !self.span.filter_generated(Some(fn_data.span), item.span) { @@ -547,7 +547,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { self.nest(item.id, |v| v.visit_block(&body)); } - fn process_static_or_const_item(&mut self, item: &ast::Item, typ: &ast::Ty, expr: &ast::Expr) { + fn process_static_or_const_item(&mut self, + item: &'l ast::Item, + typ: &'l ast::Ty, + expr: &'l ast::Expr) { if let Some(var_data) = self.save_ctxt.get_item_data(item) { down_cast_data!(var_data, VariableData, item.span); if !self.span.filter_generated(Some(var_data.span), item.span) { @@ -562,11 +565,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { id: ast::NodeId, name: ast::Name, span: Span, - typ: &ast::Ty, - expr: &ast::Expr, + typ: &'l ast::Ty, + expr: &'l ast::Expr, parent_id: DefId, vis: Visibility, - attrs: &[Attribute]) { + attrs: &'l [Attribute]) { let qualname = format!("::{}", self.tcx.node_path_str(id)); let sub_span = self.span.sub_span_after_keyword(span, keywords::Const); @@ -594,9 +597,9 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { // FIXME tuple structs should generate tuple-specific data. fn process_struct(&mut self, - item: &ast::Item, - def: &ast::VariantData, - ty_params: &ast::Generics) { + item: &'l ast::Item, + def: &'l ast::VariantData, + ty_params: &'l ast::Generics) { let name = item.ident.to_string(); let qualname = format!("::{}", self.tcx.node_path_str(item.id)); @@ -641,9 +644,9 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } fn process_enum(&mut self, - item: &ast::Item, - enum_definition: &ast::EnumDef, - ty_params: &ast::Generics) { + item: &'l ast::Item, + enum_definition: &'l ast::EnumDef, + ty_params: &'l ast::Generics) { let enum_data = self.save_ctxt.get_item_data(item); let enum_data = match enum_data { None => return, @@ -721,11 +724,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } fn process_impl(&mut self, - item: &ast::Item, - type_parameters: &ast::Generics, - trait_ref: &Option, - typ: &ast::Ty, - impl_items: &[ast::ImplItem]) { + item: &'l ast::Item, + type_parameters: &'l ast::Generics, + trait_ref: &'l Option, + typ: &'l ast::Ty, + impl_items: &'l [ast::ImplItem]) { let mut has_self_ref = false; if let Some(impl_data) = self.save_ctxt.get_item_data(item) { down_cast_data!(impl_data, ImplData, item.span); @@ -764,10 +767,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } fn process_trait(&mut self, - item: &ast::Item, - generics: &ast::Generics, - trait_refs: &ast::TyParamBounds, - methods: &[ast::TraitItem]) { + item: &'l ast::Item, + generics: &'l ast::Generics, + trait_refs: &'l ast::TyParamBounds, + methods: &'l [ast::TraitItem]) { let name = item.ident.to_string(); let qualname = format!("::{}", self.tcx.node_path_str(item.id)); let mut val = name.clone(); @@ -938,11 +941,11 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } fn process_struct_lit(&mut self, - ex: &ast::Expr, - path: &ast::Path, - fields: &Vec, - variant: &ty::VariantDef, - base: &Option>) { + ex: &'l ast::Expr, + path: &'l ast::Path, + fields: &'l [ast::Field], + variant: &'l ty::VariantDef, + base: &'l Option>) { self.write_sub_paths_truncated(path, false); if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) { @@ -969,7 +972,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { walk_list!(self, visit_expr, base); } - fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec>) { + fn process_method_call(&mut self, ex: &'l ast::Expr, args: &'l [P]) { if let Some(mcd) = self.save_ctxt.get_expr_data(ex) { down_cast_data!(mcd, MethodCallData, ex.span); if !self.span.filter_generated(Some(mcd.span), ex.span) { @@ -981,7 +984,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { walk_list!(self, visit_expr, args); } - fn process_pat(&mut self, p: &ast::Pat) { + fn process_pat(&mut self, p: &'l ast::Pat) { match p.node { PatKind::Struct(ref path, ref fields, _) => { visit::walk_path(self, path); @@ -1014,7 +1017,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } - fn process_var_decl(&mut self, p: &ast::Pat, value: String) { + fn process_var_decl(&mut self, p: &'l ast::Pat, value: String) { // The local could declare multiple new vars, we must walk the // pattern and collect them all. let mut collector = PathCollector::new(); @@ -1105,7 +1108,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } } - fn process_trait_item(&mut self, trait_item: &ast::TraitItem, trait_id: DefId) { + fn process_trait_item(&mut self, trait_item: &'l ast::TraitItem, trait_id: DefId) { self.process_macro_use(trait_item.span, trait_item.id); match trait_item.node { ast::TraitItemKind::Const(ref ty, Some(ref expr)) => { @@ -1133,7 +1136,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } } - fn process_impl_item(&mut self, impl_item: &ast::ImplItem, impl_id: DefId) { + fn process_impl_item(&mut self, impl_item: &'l ast::ImplItem, impl_id: DefId) { self.process_macro_use(impl_item.span, impl_item.id); match impl_item.node { ast::ImplItemKind::Const(ref ty, ref expr) => { @@ -1161,8 +1164,8 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> { } } -impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> { - fn visit_item(&mut self, item: &ast::Item) { +impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'l> for DumpVisitor<'l, 'tcx, 'll, D> { + fn visit_item(&mut self, item: &'l ast::Item) { use syntax::ast::ItemKind::*; self.process_macro_use(item.span, item.id); match item.node { @@ -1306,7 +1309,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> } } - fn visit_generics(&mut self, generics: &ast::Generics) { + fn visit_generics(&mut self, generics: &'l ast::Generics) { for param in generics.ty_params.iter() { for bound in param.bounds.iter() { if let ast::TraitTyParamBound(ref trait_ref, _) = *bound { @@ -1319,7 +1322,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> } } - fn visit_ty(&mut self, t: &ast::Ty) { + fn visit_ty(&mut self, t: &'l ast::Ty) { self.process_macro_use(t.span, t.id); match t.node { ast::TyKind::Path(_, ref path) => { @@ -1343,7 +1346,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> } } - fn visit_expr(&mut self, ex: &ast::Expr) { + fn visit_expr(&mut self, ex: &'l ast::Expr) { self.process_macro_use(ex.span, ex.id); match ex.node { ast::ExprKind::Call(ref _f, ref _args) => { @@ -1451,17 +1454,17 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> } } - fn visit_mac(&mut self, mac: &ast::Mac) { + fn visit_mac(&mut self, mac: &'l ast::Mac) { // These shouldn't exist in the AST at this point, log a span bug. span_bug!(mac.span, "macro invocation should have been expanded out of AST"); } - fn visit_pat(&mut self, p: &ast::Pat) { + fn visit_pat(&mut self, p: &'l ast::Pat) { self.process_macro_use(p.span, p.id); self.process_pat(p); } - fn visit_arm(&mut self, arm: &ast::Arm) { + fn visit_arm(&mut self, arm: &'l ast::Arm) { let mut collector = PathCollector::new(); for pattern in &arm.pats { // collect paths from the arm's patterns @@ -1524,12 +1527,12 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D> self.visit_expr(&arm.body); } - fn visit_stmt(&mut self, s: &ast::Stmt) { + fn visit_stmt(&mut self, s: &'l ast::Stmt) { self.process_macro_use(s.span, s.id); visit::walk_stmt(self, s) } - fn visit_local(&mut self, l: &ast::Local) { + fn visit_local(&mut self, l: &'l ast::Local) { self.process_macro_use(l.span, l.id); let value = l.init.as_ref().map(|i| self.span.snippet(i.span)).unwrap_or(String::new()); self.process_var_decl(&l.pat, value); diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 33b9f8c9034e8..b5cf8141da29c 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -741,7 +741,7 @@ impl PathCollector { } } -impl Visitor for PathCollector { +impl<'a> Visitor<'a> for PathCollector { fn visit_pat(&mut self, p: &ast::Pat) { match p.node { PatKind::Struct(ref path, ..) => { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4138acafac69a..e3979926680a1 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -85,7 +85,7 @@ macro_rules! expansions { } } - pub fn visit_with(&self, visitor: &mut V) { + pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) { match *self { Expansion::OptExpr(Some(ref expr)) => visitor.visit_expr(expr), Expansion::OptExpr(None) => {} diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 29854260899e7..4d4eecdb65246 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1014,7 +1014,7 @@ fn starts_with_digit(s: &str) -> bool { s.as_bytes().first().cloned().map_or(false, |b| b >= b'0' && b <= b'9') } -impl<'a> Visitor for PostExpansionVisitor<'a> { +impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_attribute(&mut self, attr: &ast::Attribute) { if !self.context.cm.span_allows_unstable(attr.span) { // check for gated attributes @@ -1035,7 +1035,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { } } - fn visit_item(&mut self, i: &ast::Item) { + fn visit_item(&mut self, i: &'a ast::Item) { match i.node { ast::ItemKind::ExternCrate(_) => { if attr::contains_name(&i.attrs[..], "macro_reexport") { @@ -1128,7 +1128,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_item(self, i); } - fn visit_foreign_item(&mut self, i: &ast::ForeignItem) { + fn visit_foreign_item(&mut self, i: &'a ast::ForeignItem) { let links_to_llvm = match attr::first_attr_value_str_by_name(&i.attrs, "link_name") { Some(val) => val.as_str().starts_with("llvm."), _ => false @@ -1141,7 +1141,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_foreign_item(self, i) } - fn visit_ty(&mut self, ty: &ast::Ty) { + fn visit_ty(&mut self, ty: &'a ast::Ty) { match ty.node { ast::TyKind::BareFn(ref bare_fn_ty) => { self.check_abi(bare_fn_ty.abi, ty.span); @@ -1159,7 +1159,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_ty(self, ty) } - fn visit_fn_ret_ty(&mut self, ret_ty: &ast::FunctionRetTy) { + fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) { if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty { match output_ty.node { ast::TyKind::Never => return, @@ -1169,7 +1169,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { } } - fn visit_expr(&mut self, e: &ast::Expr) { + fn visit_expr(&mut self, e: &'a ast::Expr) { match e.node { ast::ExprKind::Box(_) => { gate_feature_post!(&self, box_syntax, e.span, EXPLAIN_BOX_SYNTAX); @@ -1208,7 +1208,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_expr(self, e); } - fn visit_pat(&mut self, pattern: &ast::Pat) { + fn visit_pat(&mut self, pattern: &'a ast::Pat) { match pattern.node { PatKind::Slice(_, Some(_), ref last) if !last.is_empty() => { gate_feature_post!(&self, advanced_slice_patterns, @@ -1242,8 +1242,8 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { } fn visit_fn(&mut self, - fn_kind: FnKind, - fn_decl: &ast::FnDecl, + fn_kind: FnKind<'a>, + fn_decl: &'a ast::FnDecl, span: Span, _node_id: NodeId) { // check for const fn declarations @@ -1269,7 +1269,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_fn(self, fn_kind, fn_decl, span); } - fn visit_trait_item(&mut self, ti: &ast::TraitItem) { + fn visit_trait_item(&mut self, ti: &'a ast::TraitItem) { match ti.node { ast::TraitItemKind::Const(..) => { gate_feature_post!(&self, associated_consts, @@ -1293,7 +1293,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_trait_item(self, ti); } - fn visit_impl_item(&mut self, ii: &ast::ImplItem) { + fn visit_impl_item(&mut self, ii: &'a ast::ImplItem) { if ii.defaultness == ast::Defaultness::Default { gate_feature_post!(&self, specialization, ii.span, @@ -1316,7 +1316,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_impl_item(self, ii); } - fn visit_vis(&mut self, vis: &ast::Visibility) { + fn visit_vis(&mut self, vis: &'a ast::Visibility) { let span = match *vis { ast::Visibility::Crate(span) => span, ast::Visibility::Restricted { ref path, .. } => path.span, @@ -1327,7 +1327,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_vis(self, vis) } - fn visit_generics(&mut self, g: &ast::Generics) { + fn visit_generics(&mut self, g: &'a ast::Generics) { for t in &g.ty_params { if !t.attrs.is_empty() { gate_feature_post!(&self, generic_param_attrs, t.attrs[0].span, @@ -1337,7 +1337,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { visit::walk_generics(self, g) } - fn visit_lifetime_def(&mut self, lifetime_def: &ast::LifetimeDef) { + fn visit_lifetime_def(&mut self, lifetime_def: &'a ast::LifetimeDef) { if !lifetime_def.attrs.is_empty() { gate_feature_post!(&self, generic_param_attrs, lifetime_def.attrs[0].span, "attributes on lifetime bindings are experimental"); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index bfaf00a3d3f08..e5b66f889583a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -940,8 +940,8 @@ mod tests { struct PatIdentVisitor { spans: Vec } - impl ::visit::Visitor for PatIdentVisitor { - fn visit_pat(&mut self, p: &ast::Pat) { + impl<'a> ::visit::Visitor<'a> for PatIdentVisitor { + fn visit_pat(&mut self, p: &'a ast::Pat) { match p.node { PatKind::Ident(_ , ref spannedident, _) => { self.spans.push(spannedident.span.clone()); diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index 928ffb202d0b3..263a4f13c1b29 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -44,29 +44,29 @@ struct ShowSpanVisitor<'a> { mode: Mode, } -impl<'a> Visitor for ShowSpanVisitor<'a> { - fn visit_expr(&mut self, e: &ast::Expr) { +impl<'a> Visitor<'a> for ShowSpanVisitor<'a> { + fn visit_expr(&mut self, e: &'a ast::Expr) { if let Mode::Expression = self.mode { self.span_diagnostic.span_warn(e.span, "expression"); } visit::walk_expr(self, e); } - fn visit_pat(&mut self, p: &ast::Pat) { + fn visit_pat(&mut self, p: &'a ast::Pat) { if let Mode::Pattern = self.mode { self.span_diagnostic.span_warn(p.span, "pattern"); } visit::walk_pat(self, p); } - fn visit_ty(&mut self, t: &ast::Ty) { + fn visit_ty(&mut self, t: &'a ast::Ty) { if let Mode::Type = self.mode { self.span_diagnostic.span_warn(t.span, "type"); } visit::walk_ty(self, t); } - fn visit_mac(&mut self, mac: &ast::Mac) { + fn visit_mac(&mut self, mac: &'a ast::Mac) { visit::walk_mac(self, mac); } } diff --git a/src/libsyntax/util/node_count.rs b/src/libsyntax/util/node_count.rs index a1f07381db705..b90802d1e7eb8 100644 --- a/src/libsyntax/util/node_count.rs +++ b/src/libsyntax/util/node_count.rs @@ -26,7 +26,7 @@ impl NodeCounter { } } -impl Visitor for NodeCounter { +impl<'ast> Visitor<'ast> for NodeCounter { fn visit_ident(&mut self, span: Span, ident: Ident) { self.count += 1; walk_ident(self, span, ident); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index da36225fb329c..3e0353d532d88 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -49,56 +49,56 @@ pub enum FnKind<'a> { /// explicitly, you need to override each method. (And you also need /// to monitor future changes to `Visitor` in case a new method with a /// new default implementation gets introduced.) -pub trait Visitor: Sized { +pub trait Visitor<'ast>: Sized { fn visit_name(&mut self, _span: Span, _name: Name) { // Nothing to do. } fn visit_ident(&mut self, span: Span, ident: Ident) { walk_ident(self, span, ident); } - fn visit_mod(&mut self, m: &Mod, _s: Span, _n: NodeId) { walk_mod(self, m) } - fn visit_foreign_item(&mut self, i: &ForeignItem) { walk_foreign_item(self, i) } - fn visit_item(&mut self, i: &Item) { walk_item(self, i) } - fn visit_local(&mut self, l: &Local) { walk_local(self, l) } - fn visit_block(&mut self, b: &Block) { walk_block(self, b) } - fn visit_stmt(&mut self, s: &Stmt) { walk_stmt(self, s) } - fn visit_arm(&mut self, a: &Arm) { walk_arm(self, a) } - fn visit_pat(&mut self, p: &Pat) { walk_pat(self, p) } - fn visit_expr(&mut self, ex: &Expr) { walk_expr(self, ex) } - fn visit_expr_post(&mut self, _ex: &Expr) { } - fn visit_ty(&mut self, t: &Ty) { walk_ty(self, t) } - fn visit_generics(&mut self, g: &Generics) { walk_generics(self, g) } - fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, s: Span, _: NodeId) { + fn visit_mod(&mut self, m: &'ast Mod, _s: Span, _n: NodeId) { walk_mod(self, m) } + fn visit_foreign_item(&mut self, i: &'ast ForeignItem) { walk_foreign_item(self, i) } + fn visit_item(&mut self, i: &'ast Item) { walk_item(self, i) } + fn visit_local(&mut self, l: &'ast Local) { walk_local(self, l) } + fn visit_block(&mut self, b: &'ast Block) { walk_block(self, b) } + fn visit_stmt(&mut self, s: &'ast Stmt) { walk_stmt(self, s) } + fn visit_arm(&mut self, a: &'ast Arm) { walk_arm(self, a) } + fn visit_pat(&mut self, p: &'ast Pat) { walk_pat(self, p) } + fn visit_expr(&mut self, ex: &'ast Expr) { walk_expr(self, ex) } + fn visit_expr_post(&mut self, _ex: &'ast Expr) { } + fn visit_ty(&mut self, t: &'ast Ty) { walk_ty(self, t) } + fn visit_generics(&mut self, g: &'ast Generics) { walk_generics(self, g) } + fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl, s: Span, _: NodeId) { walk_fn(self, fk, fd, s) } - fn visit_trait_item(&mut self, ti: &TraitItem) { walk_trait_item(self, ti) } - fn visit_impl_item(&mut self, ii: &ImplItem) { walk_impl_item(self, ii) } - fn visit_trait_ref(&mut self, t: &TraitRef) { walk_trait_ref(self, t) } - fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) { + fn visit_trait_item(&mut self, ti: &'ast TraitItem) { walk_trait_item(self, ti) } + fn visit_impl_item(&mut self, ii: &'ast ImplItem) { walk_impl_item(self, ii) } + fn visit_trait_ref(&mut self, t: &'ast TraitRef) { walk_trait_ref(self, t) } + fn visit_ty_param_bound(&mut self, bounds: &'ast TyParamBound) { walk_ty_param_bound(self, bounds) } - fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) { walk_poly_trait_ref(self, t, m) } - fn visit_variant_data(&mut self, s: &VariantData, _: Ident, - _: &Generics, _: NodeId, _: Span) { + fn visit_variant_data(&mut self, s: &'ast VariantData, _: Ident, + _: &'ast Generics, _: NodeId, _: Span) { walk_struct_def(self, s) } - fn visit_struct_field(&mut self, s: &StructField) { walk_struct_field(self, s) } - fn visit_enum_def(&mut self, enum_definition: &EnumDef, - generics: &Generics, item_id: NodeId, _: Span) { + fn visit_struct_field(&mut self, s: &'ast StructField) { walk_struct_field(self, s) } + fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef, + generics: &'ast Generics, item_id: NodeId, _: Span) { walk_enum_def(self, enum_definition, generics, item_id) } - fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) { + fn visit_variant(&mut self, v: &'ast Variant, g: &'ast Generics, item_id: NodeId) { walk_variant(self, v, g, item_id) } - fn visit_lifetime(&mut self, lifetime: &Lifetime) { + fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) { walk_lifetime(self, lifetime) } - fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) { + fn visit_lifetime_def(&mut self, lifetime: &'ast LifetimeDef) { walk_lifetime_def(self, lifetime) } - fn visit_mac(&mut self, _mac: &Mac) { + fn visit_mac(&mut self, _mac: &'ast Mac) { panic!("visit_mac disabled by default"); // NB: see note about macros above. // if you really want a visitor that @@ -106,29 +106,29 @@ pub trait Visitor: Sized { // definition in your trait impl: // visit::walk_mac(self, _mac) } - fn visit_path(&mut self, path: &Path, _id: NodeId) { + fn visit_path(&mut self, path: &'ast Path, _id: NodeId) { walk_path(self, path) } - fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) { + fn visit_path_list_item(&mut self, prefix: &'ast Path, item: &'ast PathListItem) { walk_path_list_item(self, prefix, item) } - fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) { + fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) { walk_path_segment(self, path_span, path_segment) } - fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) { + fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'ast PathParameters) { walk_path_parameters(self, path_span, path_parameters) } - fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) { + fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) { walk_assoc_type_binding(self, type_binding) } - fn visit_attribute(&mut self, _attr: &Attribute) {} - fn visit_macro_def(&mut self, macro_def: &MacroDef) { + fn visit_attribute(&mut self, _attr: &'ast Attribute) {} + fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) { walk_macro_def(self, macro_def) } - fn visit_vis(&mut self, vis: &Visibility) { + fn visit_vis(&mut self, vis: &'ast Visibility) { walk_vis(self, vis) } - fn visit_fn_ret_ty(&mut self, ret_ty: &FunctionRetTy) { + fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FunctionRetTy) { walk_fn_ret_ty(self, ret_ty) } } @@ -147,45 +147,46 @@ macro_rules! walk_list { } } -pub fn walk_opt_name(visitor: &mut V, span: Span, opt_name: Option) { +pub fn walk_opt_name<'a, V: Visitor<'a>>(visitor: &mut V, span: Span, opt_name: Option) { if let Some(name) = opt_name { visitor.visit_name(span, name); } } -pub fn walk_opt_ident(visitor: &mut V, span: Span, opt_ident: Option) { +pub fn walk_opt_ident<'a, V: Visitor<'a>>(visitor: &mut V, span: Span, opt_ident: Option) { if let Some(ident) = opt_ident { visitor.visit_ident(span, ident); } } -pub fn walk_opt_sp_ident(visitor: &mut V, opt_sp_ident: &Option>) { +pub fn walk_opt_sp_ident<'a, V: Visitor<'a>>(visitor: &mut V, + opt_sp_ident: &Option>) { if let Some(ref sp_ident) = *opt_sp_ident { visitor.visit_ident(sp_ident.span, sp_ident.node); } } -pub fn walk_ident(visitor: &mut V, span: Span, ident: Ident) { +pub fn walk_ident<'a, V: Visitor<'a>>(visitor: &mut V, span: Span, ident: Ident) { visitor.visit_name(span, ident.name); } -pub fn walk_crate(visitor: &mut V, krate: &Crate) { +pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) { visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID); walk_list!(visitor, visit_attribute, &krate.attrs); walk_list!(visitor, visit_macro_def, &krate.exported_macros); } -pub fn walk_macro_def(visitor: &mut V, macro_def: &MacroDef) { +pub fn walk_macro_def<'a, V: Visitor<'a>>(visitor: &mut V, macro_def: &'a MacroDef) { visitor.visit_ident(macro_def.span, macro_def.ident); walk_opt_ident(visitor, macro_def.span, macro_def.imported_from); walk_list!(visitor, visit_attribute, ¯o_def.attrs); } -pub fn walk_mod(visitor: &mut V, module: &Mod) { +pub fn walk_mod<'a, V: Visitor<'a>>(visitor: &mut V, module: &'a Mod) { walk_list!(visitor, visit_item, &module.items); } -pub fn walk_local(visitor: &mut V, local: &Local) { +pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) { for attr in local.attrs.iter() { visitor.visit_attribute(attr); } @@ -194,28 +195,30 @@ pub fn walk_local(visitor: &mut V, local: &Local) { walk_list!(visitor, visit_expr, &local.init); } -pub fn walk_lifetime(visitor: &mut V, lifetime: &Lifetime) { +pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) { visitor.visit_name(lifetime.span, lifetime.name); } -pub fn walk_lifetime_def(visitor: &mut V, lifetime_def: &LifetimeDef) { +pub fn walk_lifetime_def<'a, V: Visitor<'a>>(visitor: &mut V, lifetime_def: &'a LifetimeDef) { visitor.visit_lifetime(&lifetime_def.lifetime); walk_list!(visitor, visit_lifetime, &lifetime_def.bounds); walk_list!(visitor, visit_attribute, &*lifetime_def.attrs); } -pub fn walk_poly_trait_ref(visitor: &mut V, trait_ref: &PolyTraitRef, _: &TraitBoundModifier) - where V: Visitor, +pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, + trait_ref: &'a PolyTraitRef, + _: &TraitBoundModifier) + where V: Visitor<'a>, { walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes); visitor.visit_trait_ref(&trait_ref.trait_ref); } -pub fn walk_trait_ref(visitor: &mut V, trait_ref: &TraitRef) { +pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) { visitor.visit_path(&trait_ref.path, trait_ref.ref_id) } -pub fn walk_item(visitor: &mut V, item: &Item) { +pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_vis(&item.vis); visitor.visit_ident(item.span, item.ident); match item.node { @@ -294,15 +297,18 @@ pub fn walk_item(visitor: &mut V, item: &Item) { walk_list!(visitor, visit_attribute, &item.attrs); } -pub fn walk_enum_def(visitor: &mut V, - enum_definition: &EnumDef, - generics: &Generics, +pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V, + enum_definition: &'a EnumDef, + generics: &'a Generics, item_id: NodeId) { walk_list!(visitor, visit_variant, &enum_definition.variants, generics, item_id); } -pub fn walk_variant(visitor: &mut V, variant: &Variant, generics: &Generics, item_id: NodeId) - where V: Visitor, +pub fn walk_variant<'a, V>(visitor: &mut V, + variant: &'a Variant, + generics: &'a Generics, + item_id: NodeId) + where V: Visitor<'a>, { visitor.visit_ident(variant.span, variant.node.name); visitor.visit_variant_data(&variant.node.data, variant.node.name, @@ -311,7 +317,7 @@ pub fn walk_variant(visitor: &mut V, variant: &Variant, generics: &Generics, walk_list!(visitor, visit_attribute, &variant.node.attrs); } -pub fn walk_ty(visitor: &mut V, typ: &Ty) { +pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { match typ.node { TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => { visitor.visit_ty(ty) @@ -361,24 +367,30 @@ pub fn walk_ty(visitor: &mut V, typ: &Ty) { } } -pub fn walk_path(visitor: &mut V, path: &Path) { +pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) { for segment in &path.segments { visitor.visit_path_segment(path.span, segment); } } -pub fn walk_path_list_item(visitor: &mut V, _prefix: &Path, item: &PathListItem) { +pub fn walk_path_list_item<'a, V: Visitor<'a>>(visitor: &mut V, + _prefix: &Path, + item: &'a PathListItem) { visitor.visit_ident(item.span, item.node.name); walk_opt_ident(visitor, item.span, item.node.rename); } -pub fn walk_path_segment(visitor: &mut V, path_span: Span, segment: &PathSegment) { +pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, + path_span: Span, + segment: &'a PathSegment) { visitor.visit_ident(path_span, segment.identifier); visitor.visit_path_parameters(path_span, &segment.parameters); } -pub fn walk_path_parameters(visitor: &mut V, _path_span: Span, path_parameters: &PathParameters) - where V: Visitor, +pub fn walk_path_parameters<'a, V>(visitor: &mut V, + _path_span: Span, + path_parameters: &'a PathParameters) + where V: Visitor<'a>, { match *path_parameters { PathParameters::AngleBracketed(ref data) => { @@ -393,12 +405,13 @@ pub fn walk_path_parameters(visitor: &mut V, _path_span: Span, path_parameter } } -pub fn walk_assoc_type_binding(visitor: &mut V, type_binding: &TypeBinding) { +pub fn walk_assoc_type_binding<'a, V: Visitor<'a>>(visitor: &mut V, + type_binding: &'a TypeBinding) { visitor.visit_ident(type_binding.span, type_binding.ident); visitor.visit_ty(&type_binding.ty); } -pub fn walk_pat(visitor: &mut V, pattern: &Pat) { +pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) { match pattern.node { PatKind::TupleStruct(ref path, ref children, _) => { visitor.visit_path(path, pattern.id); @@ -443,7 +456,7 @@ pub fn walk_pat(visitor: &mut V, pattern: &Pat) { } } -pub fn walk_foreign_item(visitor: &mut V, foreign_item: &ForeignItem) { +pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, foreign_item: &'a ForeignItem) { visitor.visit_vis(&foreign_item.vis); visitor.visit_ident(foreign_item.span, foreign_item.ident); @@ -458,7 +471,7 @@ pub fn walk_foreign_item(visitor: &mut V, foreign_item: &ForeignItem walk_list!(visitor, visit_attribute, &foreign_item.attrs); } -pub fn walk_ty_param_bound(visitor: &mut V, bound: &TyParamBound) { +pub fn walk_ty_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a TyParamBound) { match *bound { TraitTyParamBound(ref typ, ref modifier) => { visitor.visit_poly_trait_ref(typ, modifier); @@ -469,7 +482,7 @@ pub fn walk_ty_param_bound(visitor: &mut V, bound: &TyParamBound) { } } -pub fn walk_generics(visitor: &mut V, generics: &Generics) { +pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) { for param in &generics.ty_params { visitor.visit_ident(param.span, param.ident); walk_list!(visitor, visit_ty_param_bound, ¶m.bounds); @@ -504,13 +517,13 @@ pub fn walk_generics(visitor: &mut V, generics: &Generics) { } } -pub fn walk_fn_ret_ty(visitor: &mut V, ret_ty: &FunctionRetTy) { +pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FunctionRetTy) { if let FunctionRetTy::Ty(ref output_ty) = *ret_ty { visitor.visit_ty(output_ty) } } -pub fn walk_fn_decl(visitor: &mut V, function_declaration: &FnDecl) { +pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &'a FnDecl) { for argument in &function_declaration.inputs { visitor.visit_pat(&argument.pat); visitor.visit_ty(&argument.ty) @@ -518,8 +531,8 @@ pub fn walk_fn_decl(visitor: &mut V, function_declaration: &FnDecl) visitor.visit_fn_ret_ty(&function_declaration.output) } -pub fn walk_fn(visitor: &mut V, kind: FnKind, declaration: &FnDecl, _span: Span) - where V: Visitor, +pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl, _span: Span) + where V: Visitor<'a>, { match kind { FnKind::ItemFn(_, generics, _, _, _, _, body) => { @@ -539,7 +552,7 @@ pub fn walk_fn(visitor: &mut V, kind: FnKind, declaration: &FnDecl, _span: Sp } } -pub fn walk_trait_item(visitor: &mut V, trait_item: &TraitItem) { +pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a TraitItem) { visitor.visit_ident(trait_item.span, trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); match trait_item.node { @@ -565,7 +578,7 @@ pub fn walk_trait_item(visitor: &mut V, trait_item: &TraitItem) { } } -pub fn walk_impl_item(visitor: &mut V, impl_item: &ImplItem) { +pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplItem) { visitor.visit_vis(&impl_item.vis); visitor.visit_ident(impl_item.span, impl_item.ident); walk_list!(visitor, visit_attribute, &impl_item.attrs); @@ -587,22 +600,22 @@ pub fn walk_impl_item(visitor: &mut V, impl_item: &ImplItem) { } } -pub fn walk_struct_def(visitor: &mut V, struct_definition: &VariantData) { +pub fn walk_struct_def<'a, V: Visitor<'a>>(visitor: &mut V, struct_definition: &'a VariantData) { walk_list!(visitor, visit_struct_field, struct_definition.fields()); } -pub fn walk_struct_field(visitor: &mut V, struct_field: &StructField) { +pub fn walk_struct_field<'a, V: Visitor<'a>>(visitor: &mut V, struct_field: &'a StructField) { visitor.visit_vis(&struct_field.vis); walk_opt_ident(visitor, struct_field.span, struct_field.ident); visitor.visit_ty(&struct_field.ty); walk_list!(visitor, visit_attribute, &struct_field.attrs); } -pub fn walk_block(visitor: &mut V, block: &Block) { +pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) { walk_list!(visitor, visit_stmt, &block.stmts); } -pub fn walk_stmt(visitor: &mut V, statement: &Stmt) { +pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) { match statement.node { StmtKind::Local(ref local) => visitor.visit_local(local), StmtKind::Item(ref item) => visitor.visit_item(item), @@ -619,11 +632,11 @@ pub fn walk_stmt(visitor: &mut V, statement: &Stmt) { } } -pub fn walk_mac(_: &mut V, _: &Mac) { +pub fn walk_mac<'a, V: Visitor<'a>>(_: &mut V, _: &Mac) { // Empty! } -pub fn walk_expr(visitor: &mut V, expression: &Expr) { +pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { for attr in expression.attrs.iter() { visitor.visit_attribute(attr); } @@ -776,14 +789,14 @@ pub fn walk_expr(visitor: &mut V, expression: &Expr) { visitor.visit_expr_post(expression) } -pub fn walk_arm(visitor: &mut V, arm: &Arm) { +pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) { walk_list!(visitor, visit_pat, &arm.pats); walk_list!(visitor, visit_expr, &arm.guard); visitor.visit_expr(&arm.body); walk_list!(visitor, visit_attribute, &arm.attrs); } -pub fn walk_vis(visitor: &mut V, vis: &Visibility) { +pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) { if let Visibility::Restricted { ref path, id } = *vis { visitor.visit_path(path, id); } diff --git a/src/libsyntax_ext/deriving/custom.rs b/src/libsyntax_ext/deriving/custom.rs index 1076a6a6d63a5..6f02a348f91dc 100644 --- a/src/libsyntax_ext/deriving/custom.rs +++ b/src/libsyntax_ext/deriving/custom.rs @@ -21,7 +21,7 @@ use syntax::visit::Visitor; struct MarkAttrs<'a>(&'a [ast::Name]); -impl<'a> Visitor for MarkAttrs<'a> { +impl<'a> Visitor<'a> for MarkAttrs<'a> { fn visit_attribute(&mut self, attr: &Attribute) { if self.0.contains(&attr.name()) { mark_used(attr); @@ -101,4 +101,3 @@ impl MultiItemModifier for CustomDerive { res } } - diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 63cd7678321ef..51199819dfcd7 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -361,8 +361,8 @@ fn find_type_parameters(ty: &ast::Ty, types: Vec>, } - impl<'a, 'b> visit::Visitor for Visitor<'a, 'b> { - fn visit_ty(&mut self, ty: &ast::Ty) { + impl<'a, 'b> visit::Visitor<'a> for Visitor<'a, 'b> { + fn visit_ty(&mut self, ty: &'a ast::Ty) { match ty.node { ast::TyKind::Path(_, ref path) if !path.global => { if let Some(segment) = path.segments.first() { diff --git a/src/libsyntax_ext/proc_macro_registrar.rs b/src/libsyntax_ext/proc_macro_registrar.rs index 6256440bc815e..8fbd11a7a6e03 100644 --- a/src/libsyntax_ext/proc_macro_registrar.rs +++ b/src/libsyntax_ext/proc_macro_registrar.rs @@ -52,14 +52,17 @@ pub fn modify(sess: &ParseSess, let ecfg = ExpansionConfig::default("proc_macro".to_string()); let mut cx = ExtCtxt::new(sess, ecfg, resolver); - let mut collect = CollectCustomDerives { - derives: Vec::new(), - in_root: true, - handler: handler, - is_proc_macro_crate: is_proc_macro_crate, - is_test_crate: is_test_crate, + let derives = { + let mut collect = CollectCustomDerives { + derives: Vec::new(), + in_root: true, + handler: handler, + is_proc_macro_crate: is_proc_macro_crate, + is_test_crate: is_test_crate, + }; + visit::walk_crate(&mut collect, &krate); + collect.derives }; - visit::walk_crate(&mut collect, &krate); if !is_proc_macro_crate { return krate @@ -79,7 +82,7 @@ pub fn modify(sess: &ParseSess, return krate; } - krate.module.items.push(mk_registrar(&mut cx, &collect.derives)); + krate.module.items.push(mk_registrar(&mut cx, &derives)); if krate.exported_macros.len() > 0 { handler.err("cannot export macro_rules! macros from a `proc-macro` \ @@ -103,8 +106,8 @@ impl<'a> CollectCustomDerives<'a> { } } -impl<'a> Visitor for CollectCustomDerives<'a> { - fn visit_item(&mut self, item: &ast::Item) { +impl<'a> Visitor<'a> for CollectCustomDerives<'a> { + fn visit_item(&mut self, item: &'a ast::Item) { // First up, make sure we're checking a bare function. If we're not then // we're just not interested in this item. // @@ -240,7 +243,7 @@ impl<'a> Visitor for CollectCustomDerives<'a> { visit::walk_item(self, item); } - fn visit_mod(&mut self, m: &ast::Mod, _s: Span, id: NodeId) { + fn visit_mod(&mut self, m: &'a ast::Mod, _s: Span, id: NodeId) { let mut prev_in_root = self.in_root; if id != ast::CRATE_NODE_ID { prev_in_root = mem::replace(&mut self.in_root, false); diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs index a424517da12f0..fc53031e7f226 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_for_crate.rs @@ -32,7 +32,7 @@ impl LintPass for Pass { } } -impl LateLintPass for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) { if !attr::contains_name(&krate.attrs, "crate_okay") { cx.span_lint(CRATE_NOT_OKAY, krate.span, @@ -43,5 +43,5 @@ impl LateLintPass for Pass { #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { - reg.register_late_lint_pass(box Pass as LateLintPassObject); + reg.register_late_lint_pass(box Pass); } diff --git a/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs b/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs index 1e9a77724a8eb..490aa0d469312 100644 --- a/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs +++ b/src/test/compile-fail-fulldeps/auxiliary/lint_group_plugin_test.rs @@ -34,7 +34,7 @@ impl LintPass for Pass { } } -impl LateLintPass for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match &*it.name.as_str() { "lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"), @@ -46,6 +46,6 @@ impl LateLintPass for Pass { #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { - reg.register_late_lint_pass(box Pass as LateLintPassObject); + reg.register_late_lint_pass(box Pass); reg.register_lint_group("lint_me", vec![TEST_LINT, PLEASE_LINT]); } diff --git a/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs b/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs index a424517da12f0..fc53031e7f226 100644 --- a/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs +++ b/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs @@ -32,7 +32,7 @@ impl LintPass for Pass { } } -impl LateLintPass for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) { if !attr::contains_name(&krate.attrs, "crate_okay") { cx.span_lint(CRATE_NOT_OKAY, krate.span, @@ -43,5 +43,5 @@ impl LateLintPass for Pass { #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { - reg.register_late_lint_pass(box Pass as LateLintPassObject); + reg.register_late_lint_pass(box Pass); } diff --git a/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs b/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs index 1e9a77724a8eb..490aa0d469312 100644 --- a/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs +++ b/src/test/run-pass-fulldeps/auxiliary/lint_group_plugin_test.rs @@ -34,7 +34,7 @@ impl LintPass for Pass { } } -impl LateLintPass for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_item(&mut self, cx: &LateContext, it: &hir::Item) { match &*it.name.as_str() { "lintme" => cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"), @@ -46,6 +46,6 @@ impl LateLintPass for Pass { #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { - reg.register_late_lint_pass(box Pass as LateLintPassObject); + reg.register_late_lint_pass(box Pass); reg.register_lint_group("lint_me", vec![TEST_LINT, PLEASE_LINT]); } diff --git a/src/test/run-pass-fulldeps/issue-37290/auxiliary/lint.rs b/src/test/run-pass-fulldeps/issue-37290/auxiliary/lint.rs index 33d072eb6a890..c6892757c682f 100644 --- a/src/test/run-pass-fulldeps/issue-37290/auxiliary/lint.rs +++ b/src/test/run-pass-fulldeps/issue-37290/auxiliary/lint.rs @@ -39,10 +39,10 @@ impl LintPass for Pass { fn get_lints(&self) -> LintArray { lint_array!(REGION_HIERARCHY) } } -impl LateLintPass for Pass { +impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { fn check_fn(&mut self, cx: &LateContext, - fk: FnKind, _: &hir::FnDecl, expr: &hir::Expr, - span: Span, node: ast::NodeId) + fk: FnKind, _: &hir::FnDecl, expr: &hir::Expr, + span: Span, node: ast::NodeId) { if let FnKind::Closure(..) = fk { return }