Skip to content

Commit

Permalink
Track the visited AST's lifetime throughout Visitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Sep 12, 2014
1 parent a09dbf2 commit 7ef6ff0
Show file tree
Hide file tree
Showing 47 changed files with 288 additions and 302 deletions.
12 changes: 6 additions & 6 deletions src/librustc/front/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'a> Context<'a> {
}
}

impl<'a> Visitor for Context<'a> {
impl<'a, 'v> Visitor<'v> for Context<'a> {
fn visit_ident(&mut self, sp: Span, id: ast::Ident) {
if !token::get_ident(id).get().is_ascii() {
self.gate_feature("non_ascii_idents", sp,
Expand Down Expand Up @@ -386,13 +386,13 @@ impl<'a> Visitor for Context<'a> {
}

fn visit_fn(&mut self,
fn_kind: &visit::FnKind,
fn_decl: &ast::FnDecl,
block: &ast::Block,
fn_kind: visit::FnKind<'v>,
fn_decl: &'v ast::FnDecl,
block: &'v ast::Block,
span: Span,
_: NodeId) {
match *fn_kind {
visit::FkItemFn(_, _, _, ref abi) if *abi == RustIntrinsic => {
match fn_kind {
visit::FkItemFn(_, _, _, abi) if abi == RustIntrinsic => {
self.gate_feature("intrinsics",
span,
"intrinsics are subject to change")
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/front/show_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct ShowSpanVisitor<'a> {
sess: &'a Session
}

impl<'a> Visitor for ShowSpanVisitor<'a> {
impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
self.sess.span_note(e.span, "expression");
visit::walk_expr(self, e);
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor for CTypesVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for CTypesVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
match ty.node {
ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id),
Expand Down Expand Up @@ -500,7 +500,7 @@ struct RawPtrDerivingVisitor<'a, 'tcx: 'a> {
cx: &'a Context<'a, 'tcx>
}

impl<'a, 'tcx> Visitor for RawPtrDerivingVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDerivingVisitor<'a, 'tcx> {
fn visit_ty(&mut self, ty: &ast::Ty) {
static MSG: &'static str = "use of `#[deriving]` with a raw pointer";
match ty.node {
Expand Down Expand Up @@ -908,9 +908,9 @@ impl LintPass for NonSnakeCase {
}

fn check_fn(&mut self, cx: &Context,
fk: &visit::FnKind, _: &ast::FnDecl,
fk: visit::FnKind, _: &ast::FnDecl,
_: &ast::Block, span: Span, _: ast::NodeId) {
match *fk {
match fk {
visit::FkMethod(ident, _, m) => match method_context(cx, m) {
PlainImpl
=> self.check_snake_case(cx, "method", ident, span),
Expand Down Expand Up @@ -1218,7 +1218,7 @@ impl LintPass for UnusedMut {
}

fn check_fn(&mut self, cx: &Context,
_: &visit::FnKind, decl: &ast::FnDecl,
_: visit::FnKind, decl: &ast::FnDecl,
_: &ast::Block, _: Span, _: ast::NodeId) {
for a in decl.inputs.iter() {
self.check_unused_mut_pat(cx, &[a.pat]);
Expand Down Expand Up @@ -1387,9 +1387,9 @@ impl LintPass for MissingDoc {
}

fn check_fn(&mut self, cx: &Context,
fk: &visit::FnKind, _: &ast::FnDecl,
fk: visit::FnKind, _: &ast::FnDecl,
_: &ast::Block, _: Span, _: ast::NodeId) {
match *fk {
match fk {
visit::FkMethod(_, _, m) => {
// If the method is an impl for a trait, don't doc.
if method_context(cx, m) == TraitImpl { return; }
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{
}
}

impl<'a, 'tcx> Visitor for Context<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
fn visit_item(&mut self, it: &ast::Item) {
self.with_lint_attrs(it.attrs.as_slice(), |cx| {
run_lints!(cx, check_item, it);
Expand Down Expand Up @@ -531,9 +531,9 @@ impl<'a, 'tcx> Visitor for Context<'a, 'tcx> {
visit::walk_stmt(self, s);
}

fn visit_fn(&mut self, fk: &FnKind, decl: &ast::FnDecl,
body: &ast::Block, span: Span, id: ast::NodeId) {
match *fk {
fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v ast::FnDecl,
body: &'v ast::Block, span: Span, id: ast::NodeId) {
match fk {
visit::FkMethod(_, _, m) => {
self.with_lint_attrs(m.attrs.as_slice(), |cx| {
run_lints!(cx, check_fn, fk, decl, body, span, id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub trait LintPass {
fn check_ty(&mut self, _: &Context, _: &ast::Ty) { }
fn check_generics(&mut self, _: &Context, _: &ast::Generics) { }
fn check_fn(&mut self, _: &Context,
_: &FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
_: FnKind, _: &ast::FnDecl, _: &ast::Block, _: Span, _: ast::NodeId) { }
fn check_ty_method(&mut self, _: &Context, _: &ast::TypeMethod) { }
fn check_trait_method(&mut self, _: &Context, _: &ast::TraitItem) { }
fn check_struct_def(&mut self, _: &Context,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn read_crates(sess: &Session,
warn_if_multiple_versions(sess.diagnostic(), &sess.cstore)
}

impl<'a> visit::Visitor for Env<'a> {
impl<'a, 'v> visit::Visitor<'v> for Env<'a> {
fn visit_view_item(&mut self, a: &ast::ViewItem) {
visit_view_item(self, a);
visit::walk_view_item(self, a);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ struct EncodeVisitor<'a,'b:'a> {
index: &'a mut Vec<entry<i64>>,
}

impl<'a,'b> visit::Visitor for EncodeVisitor<'a,'b> {
impl<'a, 'b, 'v> Visitor<'v> for EncodeVisitor<'a, 'b> {
fn visit_expr(&mut self, ex: &Expr) {
visit::walk_expr(self, ex);
my_visit_expr(ex);
Expand Down Expand Up @@ -1775,7 +1775,7 @@ fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &Crate) {
rbml_w: &'a mut Encoder<'b>,
}

impl<'a, 'b> Visitor for StructFieldVisitor<'a, 'b> {
impl<'a, 'b, 'v> Visitor<'v> for StructFieldVisitor<'a, 'b> {
fn visit_struct_field(&mut self, field: &ast::StructField) {
self.rbml_w.start_tag(tag_struct_field);
self.rbml_w.wr_tagged_u32(tag_struct_field_id, field.node.id);
Expand All @@ -1798,7 +1798,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
rbml_w: &'a mut Encoder<'c>,
}

impl<'a, 'b, 'c, 'tcx> Visitor for ImplVisitor<'a, 'b, 'c, 'tcx> {
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
fn visit_item(&mut self, item: &Item) {
match item.node {
ItemImpl(_, Some(ref trait_ref), _, _) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/borrowck/gather_loans/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ struct StaticInitializerCtxt<'a, 'tcx: 'a> {
bccx: &'a BorrowckCtxt<'a, 'tcx>
}

impl<'a, 'tcx> Visitor for StaticInitializerCtxt<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> {
fn visit_expr(&mut self, ex: &Expr) {
match ex.node {
ast::ExprAddrOf(mutbl, ref base) => {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub struct LoanDataFlowOperator;

pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;

impl<'a, 'tcx> Visitor for BorrowckCtxt<'a, 'tcx> {
fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl,
b: &Block, s: Span, n: NodeId) {
impl<'a, 'tcx, 'v> Visitor<'v> for BorrowckCtxt<'a, 'tcx> {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl,
b: &'v Block, s: Span, n: NodeId) {
borrowck_fn(self, fk, fd, b, s, n);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
}

fn borrowck_fn(this: &mut BorrowckCtxt,
fk: &FnKind,
fk: FnKind,
decl: &ast::FnDecl,
body: &ast::Block,
sp: Span,
Expand All @@ -146,7 +146,7 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
}

fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
fk: &FnKind,
fk: FnKind,
decl: &ast::FnDecl,
cfg: &cfg::CFG,
body: &ast::Block,
Expand Down Expand Up @@ -217,7 +217,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>(
let p = input.fn_parts;

let dataflow_data = build_borrowck_dataflow_data(&mut bccx,
&p.kind,
p.kind,
&*p.decl,
input.cfg,
&*p.body,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor for CheckCrateVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &Item) {
check_item(self, i);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ pub fn check_item_recursion<'a>(sess: &'a Session,
visitor.visit_item(it);
}

impl<'a> Visitor for CheckItemRecursionVisitor<'a> {
impl<'a, 'v> Visitor<'v> for CheckItemRecursionVisitor<'a> {
fn visit_item(&mut self, it: &Item) {
if self.idstack.iter().any(|x| x == &(it.id)) {
self.sess.span_fatal(self.root_it.span, "recursive constant");
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
visit::walk_crate(&mut CheckLoopVisitor { sess: sess, cx: Normal }, krate)
}

impl<'a> Visitor for CheckLoopVisitor<'a> {
impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
fn visit_item(&mut self, i: &ast::Item) {
self.with_context(Normal, |v| visit::walk_item(v, i));
}
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ enum WitnessPreference {
LeaveOutWitness
}

impl<'a, 'tcx> Visitor for MatchCheckCtxt<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> {
fn visit_expr(&mut self, ex: &Expr) {
check_expr(self, ex);
}
fn visit_local(&mut self, l: &Local) {
check_local(self, l);
}
fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, _: NodeId) {
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl,
b: &'v Block, s: Span, _: NodeId) {
check_fn(self, fk, fd, b, s);
}
}
Expand Down Expand Up @@ -868,7 +869,7 @@ fn check_local(cx: &mut MatchCheckCtxt, loc: &Local) {
}

fn check_fn(cx: &mut MatchCheckCtxt,
kind: &FnKind,
kind: FnKind,
decl: &FnDecl,
body: &Block,
sp: Span) {
Expand Down Expand Up @@ -1022,7 +1023,7 @@ struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> {
bindings_allowed: bool
}

impl<'a, 'b, 'tcx> Visitor for AtBindingPatternVisitor<'a, 'b, 'tcx> {
impl<'a, 'b, 'tcx, 'v> Visitor<'v> for AtBindingPatternVisitor<'a, 'b, 'tcx> {
fn visit_pat(&mut self, pat: &Pat) {
if !self.bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, pat) {
self.cx.tcx.sess.span_err(pat.span,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/check_rvalues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ struct RvalueContext<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>
}

impl<'a, 'tcx> visit::Visitor for RvalueContext<'a, 'tcx> {
impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
fn visit_fn(&mut self,
_: &visit::FnKind,
fd: &ast::FnDecl,
b: &ast::Block,
_: visit::FnKind<'v>,
fd: &'v ast::FnDecl,
b: &'v ast::Block,
_: Span,
_: ast::NodeId) {
let mut euv = euv::ExprUseVisitor::new(self, self.tcx);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor for CheckStaticVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for CheckStaticVisitor<'a, 'tcx> {
fn visit_item(&mut self, i: &ast::Item) {
debug!("visit_item(item={})", pprust::item_to_string(i));
match i.node {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> {

}

impl<'a, 'tcx> Visitor for ConstEvalVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for ConstEvalVisitor<'a, 'tcx> {
fn visit_ty(&mut self, t: &Ty) {
match t.node {
TyFixedLengthVec(_, expr) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>,
}
let mut formals = Formals { entry: entry, index: index };
visit::walk_fn_decl(&mut formals, decl);
impl<'a> visit::Visitor for Formals<'a> {
impl<'a, 'v> visit::Visitor<'v> for Formals<'a> {
fn visit_pat(&mut self, p: &ast::Pat) {
self.index.insert(p.id, self.entry);
visit::walk_pat(self, p)
Expand Down
23 changes: 11 additions & 12 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor for MarkSymbolVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {

fn visit_struct_def(&mut self, def: &ast::StructDef, _: ast::Ident,
_: &ast::Generics, _: ast::NodeId) {
Expand Down Expand Up @@ -329,7 +329,7 @@ struct LifeSeeder {
worklist: Vec<ast::NodeId> ,
}

impl Visitor for LifeSeeder {
impl<'v> Visitor<'v> for LifeSeeder {
fn visit_item(&mut self, item: &ast::Item) {
if has_allow_dead_code_or_lang_attr(item.attrs.as_slice()) {
self.worklist.push(item.id);
Expand All @@ -349,11 +349,11 @@ impl Visitor for LifeSeeder {
visit::walk_item(self, item);
}

fn visit_fn(&mut self, fk: &visit::FnKind,
_: &ast::FnDecl, block: &ast::Block,
fn visit_fn(&mut self, fk: visit::FnKind<'v>,
_: &'v ast::FnDecl, block: &'v ast::Block,
_: codemap::Span, id: ast::NodeId) {
// Check for method here because methods are not ast::Item
match *fk {
match fk {
visit::FkMethod(_, _, method) => {
if has_allow_dead_code_or_lang_attr(method.attrs.as_slice()) {
self.worklist.push(id);
Expand Down Expand Up @@ -499,7 +499,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor for DeadVisitor<'a, 'tcx> {
impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
fn visit_item(&mut self, item: &ast::Item) {
let ctor_id = get_struct_ctor_id(item);
if !self.symbol_is_live(item.id, ctor_id) && should_warn(item) {
Expand All @@ -515,15 +515,14 @@ impl<'a, 'tcx> Visitor for DeadVisitor<'a, 'tcx> {
visit::walk_foreign_item(self, fi);
}

fn visit_fn(&mut self, fk: &visit::FnKind,
_: &ast::FnDecl, block: &ast::Block,
fn visit_fn(&mut self, fk: visit::FnKind<'v>,
_: &'v ast::FnDecl, block: &'v ast::Block,
span: codemap::Span, id: ast::NodeId) {
// Have to warn method here because methods are not ast::Item
match *fk {
visit::FkMethod(..) => {
let ident = visit::name_of_fn(fk);
match fk {
visit::FkMethod(name, _, _) => {
if !self.symbol_is_live(id, None) {
self.warn_dead_code(id, span, ident);
self.warn_dead_code(id, span, name);
}
}
_ => ()
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor for EffectCheckVisitor<'a, 'tcx> {
fn visit_fn(&mut self, fn_kind: &visit::FnKind, fn_decl: &ast::FnDecl,
block: &ast::Block, span: Span, _: ast::NodeId) {
impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
fn visit_fn(&mut self, fn_kind: visit::FnKind<'v>, fn_decl: &'v ast::FnDecl,
block: &'v ast::Block, span: Span, _: ast::NodeId) {

let (is_item_fn, is_unsafe_fn) = match *fn_kind {
let (is_item_fn, is_unsafe_fn) = match fn_kind {
visit::FkItemFn(_, _, fn_style, _) =>
(true, fn_style == ast::UnsafeFn),
visit::FkMethod(_, _, method) =>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct EntryContext<'a> {
non_main_fns: Vec<(NodeId, Span)> ,
}

impl<'a> Visitor for EntryContext<'a> {
impl<'a, 'v> Visitor<'v> for EntryContext<'a> {
fn visit_item(&mut self, item: &Item) {
find_item(item, self);
}
Expand Down
Loading

5 comments on commit 7ef6ff0

@bors
Copy link
Contributor

@bors bors commented on 7ef6ff0 Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix
at eddyb@7ef6ff0

@bors
Copy link
Contributor

@bors bors commented on 7ef6ff0 Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/visitor = 7ef6ff0 into auto

@bors
Copy link
Contributor

@bors bors commented on 7ef6ff0 Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/visitor = 7ef6ff0 merged ok, testing candidate = 9c68679

@bors
Copy link
Contributor

@bors bors commented on 7ef6ff0 Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 7ef6ff0 Sep 12, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9c68679

Please sign in to comment.