提交 eedb9510 编写于 作者: V Vadim Petrochenkov

Fill in some missing parts in the default AST visitor

+ Add helper macro for walking lists (including Options)
上级 9e11845d
......@@ -898,12 +898,8 @@ fn visit_impl_item(&mut self, impl_item: &ast::ImplItem) {
});
}
fn visit_opt_lifetime_ref(&mut self, sp: Span, lt: &Option<ast::Lifetime>) {
run_lints!(self, check_opt_lifetime_ref, early_passes, sp, lt);
}
fn visit_lifetime_ref(&mut self, lt: &ast::Lifetime) {
run_lints!(self, check_lifetime_ref, early_passes, lt);
fn visit_lifetime(&mut self, lt: &ast::Lifetime) {
run_lints!(self, check_lifetime, early_passes, lt);
}
fn visit_lifetime_def(&mut self, lt: &ast::LifetimeDef) {
......
......@@ -199,11 +199,7 @@ fn check_struct_def_post(&mut self, _: &EarlyContext,
fn check_struct_field(&mut self, _: &EarlyContext, _: &ast::StructField) { }
fn check_variant(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
fn check_variant_post(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
fn check_opt_lifetime_ref(&mut self,
_: &EarlyContext,
_: Span,
_: &Option<ast::Lifetime>) { }
fn check_lifetime_ref(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
fn check_lifetime(&mut self, _: &EarlyContext, _: &ast::Lifetime) { }
fn check_lifetime_def(&mut self, _: &EarlyContext, _: &ast::LifetimeDef) { }
fn check_explicit_self(&mut self, _: &EarlyContext, _: &ast::ExplicitSelf) { }
fn check_path(&mut self, _: &EarlyContext, _: &ast::Path, _: ast::NodeId) { }
......
......@@ -771,7 +771,7 @@ fn process_struct_lit(&mut self,
}
}
visit::walk_expr_opt(self, base)
walk_list!(self, visit_expr, base);
}
fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
......@@ -785,7 +785,7 @@ fn process_method_call(&mut self, ex: &ast::Expr, args: &Vec<P<ast::Expr>>) {
}
// walk receiver and args
visit::walk_exprs(self, &args);
walk_list!(self, visit_expr, args);
}
fn process_pat(&mut self, p: &ast::Pat) {
......@@ -1200,7 +1200,7 @@ fn visit_arm(&mut self, arm: &ast::Arm) {
for &(id, ref path, ref_kind) in &paths_to_process {
self.process_path(id, path, ref_kind);
}
visit::walk_expr_opt(self, &arm.guard);
walk_list!(self, visit_expr, &arm.guard);
self.visit_expr(&arm.body);
}
......@@ -1246,7 +1246,7 @@ fn visit_local(&mut self, l: &ast::Local) {
}
// Just walk the initialiser and type (don't want to walk the pattern again).
visit::walk_ty_opt(self, &l.ty);
visit::walk_expr_opt(self, &l.init);
walk_list!(self, visit_ty, &l.ty);
walk_list!(self, visit_expr, &l.init);
}
}
......@@ -1613,6 +1613,13 @@ pub fn id(&self) -> NodeId {
}
}
pub fn name(&self) -> Option<Ident> {
match *self {
PathListIdent { name, .. } => Some(name),
PathListMod { .. } => None,
}
}
pub fn rename(&self) -> Option<Ident> {
match *self {
PathListIdent { rename, .. } | PathListMod { rename, .. } => rename
......
......@@ -476,12 +476,12 @@ fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
visit::walk_impl_item(self, ii);
}
fn visit_lifetime_ref(&mut self, lifetime: &Lifetime) {
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
self.operation.visit_id(lifetime.id);
}
fn visit_lifetime_def(&mut self, def: &LifetimeDef) {
self.visit_lifetime_ref(&def.lifetime);
self.visit_lifetime(&def.lifetime);
}
fn visit_trait_ref(&mut self, trait_ref: &TraitRef) {
......
......@@ -12,6 +12,7 @@
use std::fmt;
use std::iter::{IntoIterator, FromIterator};
use std::ops::Deref;
use std::slice;
use std::vec;
use serialize::{Encodable, Decodable, Encoder, Decoder};
......@@ -82,6 +83,14 @@ fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> OwnedSlice<T> {
}
}
impl<'a, T> IntoIterator for &'a OwnedSlice<T> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.data.into_iter()
}
}
impl<T: Encodable> Encodable for OwnedSlice<T> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
Encodable::encode(&**self, s)
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册