Skip to content

Commit eedb951

Browse files
committed
Fill in some missing parts in the default AST visitor
+ Add helper macro for walking lists (including Options)
1 parent 9e11845 commit eedb951

File tree

7 files changed

+275
-357
lines changed

7 files changed

+275
-357
lines changed

src/librustc/lint/context.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,8 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
898898
});
899899
}
900900

901-
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<ast::Lifetime>) {
902-
run_lints!(self, check_opt_lifetime_ref, early_passes, sp, lt);
903-
}
904-
905-
fn visit_lifetime_ref(&mut self, lt: &ast::Lifetime) {
906-
run_lints!(self, check_lifetime_ref, early_passes, lt);
901+
fn visit_lifetime(&mut self, lt: &ast::Lifetime) {
902+
run_lints!(self, check_lifetime, early_passes, lt);
907903
}
908904

909905
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {

src/librustc/lint/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,7 @@ pub trait EarlyLintPass: LintPass {
199199
fn check_struct_field(&mut self, _: &EarlyContext, _: &ast::StructField) { }
200200
fn check_variant(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
201201
fn check_variant_post(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
202-
fn check_opt_lifetime_ref(&mut self,
203-
_: &EarlyContext,
204-
_: Span,
205-
_: &Option<ast::Lifetime>) { }
206-
fn check_lifetime_ref(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
202+
fn check_lifetime(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
207203
fn check_lifetime_def(&mut self, _: &EarlyContext, _: &ast::LifetimeDef) { }
208204
fn check_explicit_self(&mut self, _: &EarlyContext, _: &ast::ExplicitSelf) { }
209205
fn check_path(&mut self, _: &EarlyContext, _: &ast::Path, _: ast::NodeId) { }

src/librustc_trans/save/dump_csv.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
771771
}
772772
}
773773

774-
visit::walk_expr_opt(self, base)
774+
walk_list!(self, visit_expr, base);
775775
}
776776

777777
fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
@@ -785,7 +785,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
785785
}
786786

787787
// walk receiver and args
788-
visit::walk_exprs(self, &args);
788+
walk_list!(self, visit_expr, args);
789789
}
790790

791791
fn process_pat(&mut self, p: &ast::Pat) {
@@ -1200,7 +1200,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
12001200
for &(id, ref path, ref_kind) in &paths_to_process {
12011201
self.process_path(id, path, ref_kind);
12021202
}
1203-
visit::walk_expr_opt(self, &arm.guard);
1203+
walk_list!(self, visit_expr, &arm.guard);
12041204
self.visit_expr(&arm.body);
12051205
}
12061206

@@ -1246,7 +1246,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
12461246
}
12471247

12481248
// Just walk the initialiser and type (don't want to walk the pattern again).
1249-
visit::walk_ty_opt(self, &l.ty);
1250-
visit::walk_expr_opt(self, &l.init);
1249+
walk_list!(self, visit_ty, &l.ty);
1250+
walk_list!(self, visit_expr, &l.init);
12511251
}
12521252
}

src/libsyntax/ast.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,13 @@ impl PathListItem_ {
16131613
}
16141614
}
16151615

1616+
pub fn name(&self) -> Option<Ident> {
1617+
match *self {
1618+
PathListIdent { name, .. } => Some(name),
1619+
PathListMod { .. } => None,
1620+
}
1621+
}
1622+
16161623
pub fn rename(&self) -> Option<Ident> {
16171624
match *self {
16181625
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename

src/libsyntax/ast_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,12 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
476476
visit::walk_impl_item(self, ii);
477477
}
478478

479-
fn visit_lifetime_ref(&mut self, lifetime: &Lifetime) {
479+
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
480480
self.operation.visit_id(lifetime.id);
481481
}
482482

483483
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
484-
self.visit_lifetime_ref(&def.lifetime);
484+
self.visit_lifetime(&def.lifetime);
485485
}
486486

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

src/libsyntax/owned_slice.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::default::Default;
1212
use std::fmt;
1313
use std::iter::{IntoIterator, FromIterator};
1414
use std::ops::Deref;
15+
use std::slice;
1516
use std::vec;
1617
use serialize::{Encodable, Decodable, Encoder, Decoder};
1718

@@ -82,6 +83,14 @@ impl<T> FromIterator<T> for OwnedSlice<T> {
8283
}
8384
}
8485

86+
impl<'a, T> IntoIterator for &'a OwnedSlice<T> {
87+
type Item = &'a T;
88+
type IntoIter = slice::Iter<'a, T>;
89+
fn into_iter(self) -> Self::IntoIter {
90+
self.data.into_iter()
91+
}
92+
}
93+
8594
impl<T: Encodable> Encodable for OwnedSlice<T> {
8695
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
8796
Encodable::encode(&**self, s)

0 commit comments

Comments
 (0)