2015-09-28 06:26:26 -05:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
//! AST walker. Each overridden visit method has full control over what
|
|
|
|
//! happens with its node, it can do its own traversal of the node's children,
|
|
|
|
//! call `visit::walk_*` to apply the default traversal algorithm, or prevent
|
|
|
|
//! deeper traversal by doing nothing.
|
2014-06-09 15:12:30 -05:00
|
|
|
//!
|
|
|
|
//! Note: it is an important invariant that the default visitor walks the body
|
|
|
|
//! of a function in "execution order" (more concretely, reverse post-order
|
|
|
|
//! with respect to the CFG implied by the AST), meaning that if AST node A may
|
|
|
|
//! execute before AST node B, then A is visited first. The borrow checker in
|
|
|
|
//! particular relies on this property.
|
|
|
|
//!
|
2014-07-09 16:48:12 -05:00
|
|
|
//! Note: walking an AST before macro expansion is probably a bad idea. For
|
|
|
|
//! instance, a walker looking for item names in a module will miss all of
|
|
|
|
//! those that are created by the expansion of a macro.
|
|
|
|
|
2014-04-02 03:19:41 -05:00
|
|
|
use abi::Abi;
|
2012-09-04 13:37:29 -05:00
|
|
|
use ast::*;
|
2015-11-15 10:17:50 -06:00
|
|
|
use attr::ThinAttributesExt;
|
2013-08-31 11:13:04 -05:00
|
|
|
use codemap::Span;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2015-08-16 07:44:37 -05:00
|
|
|
#[derive(Copy, Clone, PartialEq, Eq)]
|
2014-01-09 07:05:33 -06:00
|
|
|
pub enum FnKind<'a> {
|
2014-06-09 15:12:30 -05:00
|
|
|
/// fn foo() or extern "Abi" fn foo()
|
2015-08-26 05:00:14 -05:00
|
|
|
ItemFn(Ident, &'a Generics, Unsafety, Constness, Abi, Visibility),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
/// fn foo(&self)
|
2015-08-26 05:00:14 -05:00
|
|
|
Method(Ident, &'a MethodSig, Option<Visibility>),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2015-08-16 07:53:58 -05:00
|
|
|
/// |x, y| {}
|
2015-08-26 05:00:14 -05:00
|
|
|
Closure,
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
|
2014-05-12 11:58:23 -05:00
|
|
|
/// Each method of the Visitor trait is a hook to be potentially
|
2014-06-08 23:00:52 -05:00
|
|
|
/// overridden. Each method's default implementation recursively visits
|
2014-05-12 11:58:23 -05:00
|
|
|
/// the substructure of the input via the corresponding `walk` method;
|
|
|
|
/// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
|
|
|
|
///
|
|
|
|
/// If you want to ensure that your code handles every variant
|
|
|
|
/// 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.)
|
2014-12-18 14:27:41 -06:00
|
|
|
pub trait Visitor<'v> : Sized {
|
2014-11-18 10:39:16 -06:00
|
|
|
fn visit_name(&mut self, _span: Span, _name: Name) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_ident(self, span, ident);
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_mod(&mut self, m: &'v Mod, _s: Span, _n: NodeId) { walk_mod(self, m) }
|
|
|
|
fn visit_foreign_item(&mut self, i: &'v ForeignItem) { walk_foreign_item(self, i) }
|
|
|
|
fn visit_item(&mut self, i: &'v Item) { walk_item(self, i) }
|
|
|
|
fn visit_local(&mut self, l: &'v Local) { walk_local(self, l) }
|
|
|
|
fn visit_block(&mut self, b: &'v Block) { walk_block(self, b) }
|
|
|
|
fn visit_stmt(&mut self, s: &'v Stmt) { walk_stmt(self, s) }
|
|
|
|
fn visit_arm(&mut self, a: &'v Arm) { walk_arm(self, a) }
|
|
|
|
fn visit_pat(&mut self, p: &'v Pat) { walk_pat(self, p) }
|
|
|
|
fn visit_decl(&mut self, d: &'v Decl) { walk_decl(self, d) }
|
|
|
|
fn visit_expr(&mut self, ex: &'v Expr) { walk_expr(self, ex) }
|
|
|
|
fn visit_expr_post(&mut self, _ex: &'v Expr) { }
|
|
|
|
fn visit_ty(&mut self, t: &'v Ty) { walk_ty(self, t) }
|
|
|
|
fn visit_generics(&mut self, g: &'v Generics) { walk_generics(self, g) }
|
|
|
|
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl, b: &'v Block, s: Span, _: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_fn(self, fk, fd, b, s)
|
|
|
|
}
|
2015-03-10 05:28:44 -05:00
|
|
|
fn visit_trait_item(&mut self, ti: &'v TraitItem) { walk_trait_item(self, ti) }
|
|
|
|
fn visit_impl_item(&mut self, ii: &'v ImplItem) { walk_impl_item(self, ii) }
|
2014-11-07 05:53:45 -06:00
|
|
|
fn visit_trait_ref(&mut self, t: &'v TraitRef) { walk_trait_ref(self, t) }
|
2014-11-15 15:55:27 -06:00
|
|
|
fn visit_ty_param_bound(&mut self, bounds: &'v TyParamBound) {
|
|
|
|
walk_ty_param_bound(self, bounds)
|
|
|
|
}
|
2014-12-24 00:38:10 -06:00
|
|
|
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifier) {
|
|
|
|
walk_poly_trait_ref(self, t, m)
|
2014-11-07 05:53:45 -06:00
|
|
|
}
|
2015-10-07 19:20:57 -05:00
|
|
|
fn visit_variant_data(&mut self, s: &'v VariantData, _: Ident,
|
2015-10-02 12:06:59 -05:00
|
|
|
_: &'v Generics, _: NodeId, _: Span) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_struct_def(self, s)
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_struct_field(&mut self, s: &'v StructField) { walk_struct_field(self, s) }
|
2015-06-22 21:55:57 -05:00
|
|
|
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef,
|
2015-10-16 09:17:14 -05:00
|
|
|
generics: &'v Generics, item_id: NodeId, _: Span) {
|
2015-10-02 08:14:20 -05:00
|
|
|
walk_enum_def(self, enum_definition, generics, item_id)
|
|
|
|
}
|
|
|
|
fn visit_variant(&mut self, v: &'v Variant, g: &'v Generics, item_id: NodeId) {
|
|
|
|
walk_variant(self, v, g, item_id)
|
2015-06-22 21:55:57 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
|
|
|
|
walk_lifetime(self, lifetime)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-11-18 10:39:16 -06:00
|
|
|
fn visit_lifetime_def(&mut self, lifetime: &'v LifetimeDef) {
|
|
|
|
walk_lifetime_def(self, lifetime)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_explicit_self(self, es)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-01-02 15:39:05 -06:00
|
|
|
fn visit_mac(&mut self, _mac: &'v Mac) {
|
2014-10-09 14:17:22 -05:00
|
|
|
panic!("visit_mac disabled by default");
|
2014-07-09 16:48:12 -05:00
|
|
|
// NB: see note about macros above.
|
|
|
|
// if you really want a visitor that
|
|
|
|
// works on macros, use this
|
|
|
|
// definition in your trait impl:
|
2015-01-02 15:39:05 -06:00
|
|
|
// visit::walk_mac(self, _mac)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_path(self, path)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2015-09-12 08:10:12 -05:00
|
|
|
fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) {
|
|
|
|
walk_path_list_item(self, prefix, item)
|
|
|
|
}
|
2014-11-15 15:55:27 -06:00
|
|
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
|
|
|
|
walk_path_segment(self, path_span, path_segment)
|
|
|
|
}
|
|
|
|
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &'v PathParameters) {
|
|
|
|
walk_path_parameters(self, path_span, path_parameters)
|
|
|
|
}
|
2014-12-28 09:07:21 -06:00
|
|
|
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding) {
|
|
|
|
walk_assoc_type_binding(self, type_binding)
|
|
|
|
}
|
2014-09-09 17:54:36 -05:00
|
|
|
fn visit_attribute(&mut self, _attr: &'v Attribute) {}
|
2015-09-28 06:26:26 -05:00
|
|
|
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
|
|
|
|
walk_macro_def(self, macro_def)
|
|
|
|
}
|
2013-08-08 07:23:25 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! walk_list {
|
2015-09-28 16:23:54 -05:00
|
|
|
($visitor: expr, $method: ident, $list: expr) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
for elem in $list {
|
|
|
|
$visitor.$method(elem)
|
|
|
|
}
|
2015-10-16 09:17:14 -05:00
|
|
|
};
|
|
|
|
($visitor: expr, $method: ident, $list: expr, $($extra_args: expr),*) => {
|
|
|
|
for elem in $list {
|
|
|
|
$visitor.$method(elem, $($extra_args,)*)
|
|
|
|
}
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
pub fn walk_opt_name<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, opt_name: Option<Name>) {
|
|
|
|
for name in opt_name {
|
|
|
|
visitor.visit_name(span, name);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
pub fn walk_opt_ident<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, opt_ident: Option<Ident>) {
|
|
|
|
for ident in opt_ident {
|
|
|
|
visitor.visit_ident(span, ident);
|
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, span: Span, ident: Ident) {
|
|
|
|
visitor.visit_name(span, ident.name);
|
2014-11-18 10:39:16 -06:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v 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<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v 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<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) {
|
|
|
|
walk_list!(visitor, visit_item, &module.items);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
|
|
|
|
visitor.visit_pat(&local.pat);
|
|
|
|
walk_list!(visitor, visit_ty, &local.ty);
|
|
|
|
walk_list!(visitor, visit_expr, &local.init);
|
2014-12-13 04:34:34 -06:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
|
|
|
|
visitor.visit_name(lifetime.span, lifetime.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
lifetime_def: &'v LifetimeDef) {
|
|
|
|
visitor.visit_lifetime(&lifetime_def.lifetime);
|
|
|
|
walk_list!(visitor, visit_lifetime, &lifetime_def.bounds);
|
2014-12-13 04:34:34 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
explicit_self: &'v ExplicitSelf) {
|
2013-10-28 16:37:10 -05:00
|
|
|
match explicit_self.node {
|
2016-02-08 08:43:56 -06:00
|
|
|
SelfKind::Static => {},
|
|
|
|
SelfKind::Value(ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(explicit_self.span, ident)
|
|
|
|
}
|
2016-02-08 08:43:56 -06:00
|
|
|
SelfKind::Region(ref opt_lifetime, _, ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(explicit_self.span, ident);
|
|
|
|
walk_list!(visitor, visit_lifetime, opt_lifetime);
|
|
|
|
}
|
2016-02-08 08:43:56 -06:00
|
|
|
SelfKind::Explicit(ref typ, ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(explicit_self.span, ident);
|
|
|
|
visitor.visit_ty(typ)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 05:53:45 -06:00
|
|
|
pub fn walk_poly_trait_ref<'v, V>(visitor: &mut V,
|
2014-12-24 00:38:10 -06:00
|
|
|
trait_ref: &'v PolyTraitRef,
|
|
|
|
_modifier: &'v TraitBoundModifier)
|
2014-11-07 05:53:45 -06:00
|
|
|
where V: Visitor<'v>
|
|
|
|
{
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_lifetime_def, &trait_ref.bound_lifetimes);
|
2014-11-07 05:53:45 -06:00
|
|
|
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_trait_ref<'v,V>(visitor: &mut V,
|
|
|
|
trait_ref: &'v TraitRef)
|
|
|
|
where V: Visitor<'v>
|
|
|
|
{
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(item.span, item.ident);
|
2013-07-19 20:42:11 -05:00
|
|
|
match item.node {
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::ExternCrate(opt_name) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_opt_name(visitor, item.span, opt_name)
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Use(ref vp) => {
|
2015-01-13 09:30:17 -06:00
|
|
|
match vp.node {
|
2015-09-28 06:26:26 -05:00
|
|
|
ViewPathSimple(ident, ref path) => {
|
|
|
|
visitor.visit_ident(vp.span, ident);
|
2015-01-13 09:30:17 -06:00
|
|
|
visitor.visit_path(path, item.id);
|
|
|
|
}
|
|
|
|
ViewPathGlob(ref path) => {
|
|
|
|
visitor.visit_path(path, item.id);
|
|
|
|
}
|
|
|
|
ViewPathList(ref prefix, ref list) => {
|
2015-09-12 08:10:12 -05:00
|
|
|
if !list.is_empty() {
|
|
|
|
for item in list {
|
|
|
|
visitor.visit_path_list_item(prefix, item)
|
2015-01-13 09:30:17 -06:00
|
|
|
}
|
2015-09-12 08:10:12 -05:00
|
|
|
} else {
|
2015-09-15 16:50:50 -05:00
|
|
|
visitor.visit_path(prefix, item.id);
|
2015-01-13 09:30:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Static(ref typ, _, ref expr) |
|
|
|
|
ItemKind::Const(ref typ, ref expr) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(typ);
|
|
|
|
visitor.visit_expr(expr);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Fn(ref declaration, unsafety, constness, abi, ref generics, ref body) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::ItemFn(item.ident, generics, unsafety,
|
|
|
|
constness, abi, item.vis),
|
2015-09-28 06:26:26 -05:00
|
|
|
declaration,
|
|
|
|
body,
|
2013-07-19 20:42:11 -05:00
|
|
|
item.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
item.id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Mod(ref module) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_mod(module, item.span, item.id)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::ForeignMod(ref foreign_module) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
|
2011-12-20 09:33:55 -06:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Ty(ref typ, ref type_parameters) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(typ);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Enum(ref enum_definition, ref type_parameters) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters);
|
2015-10-16 09:17:14 -05:00
|
|
|
visitor.visit_enum_def(enum_definition, type_parameters, item.id, item.span)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::DefaultImpl(_, ref trait_ref) => {
|
2015-01-22 15:14:52 -06:00
|
|
|
visitor.visit_trait_ref(trait_ref)
|
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Impl(_, _,
|
2014-12-10 05:15:06 -06:00
|
|
|
ref type_parameters,
|
2015-09-28 06:26:26 -05:00
|
|
|
ref opt_trait_reference,
|
2014-09-09 17:54:36 -05:00
|
|
|
ref typ,
|
2014-08-04 15:56:56 -05:00
|
|
|
ref impl_items) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(type_parameters);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_trait_ref, opt_trait_reference);
|
|
|
|
visitor.visit_ty(typ);
|
|
|
|
walk_list!(visitor, visit_impl_item, impl_items);
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Struct(ref struct_definition, ref generics) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2015-10-07 19:20:57 -05:00
|
|
|
visitor.visit_variant_data(struct_definition, item.ident,
|
2015-10-02 12:06:59 -05:00
|
|
|
generics, item.id, item.span);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Trait(_, ref generics, ref bounds, ref methods) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
walk_list!(visitor, visit_trait_item, methods);
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Mac(ref mac) => visitor.visit_mac(mac),
|
2014-06-08 01:02:48 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &item.attrs);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
enum_definition: &'v EnumDef,
|
2015-10-02 08:14:20 -05:00
|
|
|
generics: &'v Generics,
|
|
|
|
item_id: NodeId) {
|
2015-10-16 09:17:14 -05:00
|
|
|
walk_list!(visitor, visit_variant, &enum_definition.variants, generics, item_id);
|
2013-11-11 22:17:47 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
variant: &'v Variant,
|
2015-10-02 08:14:20 -05:00
|
|
|
generics: &'v Generics,
|
|
|
|
item_id: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(variant.span, variant.node.name);
|
2015-10-07 19:20:57 -05:00
|
|
|
visitor.visit_variant_data(&variant.node.data, variant.node.name,
|
2015-10-02 12:06:59 -05:00
|
|
|
generics, item_id, variant.span);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, &variant.node.disr_expr);
|
|
|
|
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
2015-01-02 05:55:31 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match typ.node {
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty)
|
2013-12-16 12:01:40 -06:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Ptr(ref mutable_type) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(&mutable_type.ty)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Rptr(ref opt_lifetime, ref mutable_type) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_lifetime, opt_lifetime);
|
|
|
|
visitor.visit_ty(&mutable_type.ty)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Tup(ref tuple_element_types) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, tuple_element_types);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::BareFn(ref function_declaration) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_fn_decl(visitor, &function_declaration.decl);
|
|
|
|
walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Path(ref maybe_qself, ref path) => {
|
2015-09-29 03:33:25 -05:00
|
|
|
if let Some(ref qself) = *maybe_qself {
|
2015-02-17 11:29:13 -06:00
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
}
|
2015-01-29 13:18:17 -06:00
|
|
|
visitor.visit_path(path, typ.id);
|
2014-11-20 14:08:48 -06:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::ObjectSum(ref ty, ref bounds) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::FixedLengthVec(ref ty, ref expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
|
|
|
visitor.visit_expr(expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::PolyTraitRef(ref bounds) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
2014-11-07 05:53:45 -06:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Typeof(ref expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(expression)
|
2013-08-22 16:00:02 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Infer => {}
|
|
|
|
TyKind::Mac(ref mac) => {
|
2015-07-25 23:30:35 -05:00
|
|
|
visitor.visit_mac(mac)
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
|
2015-01-31 11:20:46 -06:00
|
|
|
for segment in &path.segments {
|
2014-11-15 15:55:27 -06:00
|
|
|
visitor.visit_path_segment(path.span, segment);
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 06:24:49 -06:00
|
|
|
|
2015-09-12 08:10:12 -05:00
|
|
|
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, prefix: &'v Path,
|
|
|
|
item: &'v PathListItem) {
|
|
|
|
for segment in &prefix.segments {
|
|
|
|
visitor.visit_path_segment(prefix.span, segment);
|
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_opt_ident(visitor, item.span, item.node.name());
|
|
|
|
walk_opt_ident(visitor, item.span, item.node.rename());
|
2015-09-12 08:10:12 -05:00
|
|
|
}
|
|
|
|
|
2014-11-15 15:55:27 -06:00
|
|
|
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
path_span: Span,
|
|
|
|
segment: &'v PathSegment) {
|
|
|
|
visitor.visit_ident(path_span, segment.identifier);
|
|
|
|
visitor.visit_path_parameters(path_span, &segment.parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
_path_span: Span,
|
|
|
|
path_parameters: &'v PathParameters) {
|
|
|
|
match *path_parameters {
|
2015-12-22 09:56:13 -06:00
|
|
|
PathParameters::AngleBracketed(ref data) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, &data.types);
|
|
|
|
walk_list!(visitor, visit_lifetime, &data.lifetimes);
|
|
|
|
walk_list!(visitor, visit_assoc_type_binding, &data.bindings);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
2015-12-22 09:56:13 -06:00
|
|
|
PathParameters::Parenthesized(ref data) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, &data.inputs);
|
|
|
|
walk_list!(visitor, visit_ty, &data.output);
|
2013-08-07 11:47:28 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-12-13 06:19:56 -06:00
|
|
|
}
|
|
|
|
|
2014-12-28 09:07:21 -06:00
|
|
|
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
type_binding: &'v TypeBinding) {
|
|
|
|
visitor.visit_ident(type_binding.span, type_binding.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(&type_binding.ty);
|
2014-12-28 09:07:21 -06:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match pattern.node {
|
2016-02-13 06:51:27 -06:00
|
|
|
PatKind::TupleStruct(ref path, ref opt_children) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2015-09-29 03:33:25 -05:00
|
|
|
if let Some(ref children) = *opt_children {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, children);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2012-08-06 19:01:14 -05:00
|
|
|
}
|
2016-02-13 06:51:27 -06:00
|
|
|
PatKind::Path(ref path) => {
|
|
|
|
visitor.visit_path(path, pattern.id);
|
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::QPath(ref qself, ref path) => {
|
2015-03-25 11:53:28 -05:00
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
visitor.visit_path(path, pattern.id)
|
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Struct(ref path, ref fields, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2015-01-31 11:20:46 -06:00
|
|
|
for field in fields {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(field.span, field.node.ident);
|
|
|
|
visitor.visit_pat(&field.node.pat)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Tup(ref tuple_elements) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, tuple_elements);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Box(ref subpattern) |
|
|
|
|
PatKind::Ref(ref subpattern, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(subpattern)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Ident(_, ref pth1, ref optional_subpattern) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(pth1.span, pth1.node);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, optional_subpattern);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Lit(ref expression) => visitor.visit_expr(expression),
|
|
|
|
PatKind::Range(ref lower_bound, ref upper_bound) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(lower_bound);
|
|
|
|
visitor.visit_expr(upper_bound)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Wild => (),
|
|
|
|
PatKind::Vec(ref prepatterns, ref slice_pattern, ref postpatterns) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, prepatterns);
|
|
|
|
walk_list!(visitor, visit_pat, slice_pattern);
|
|
|
|
walk_list!(visitor, visit_pat, postpatterns);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Mac(ref mac) => visitor.visit_mac(mac),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
foreign_item: &'v ForeignItem) {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_ident(foreign_item.span, foreign_item.ident);
|
2013-11-22 06:24:49 -06:00
|
|
|
|
2013-07-19 20:42:11 -05:00
|
|
|
match foreign_item.node {
|
2016-02-09 04:31:19 -06:00
|
|
|
ForeignItemKind::Fn(ref function_declaration, ref generics) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_fn_decl(visitor, function_declaration);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics)
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2016-02-09 04:31:19 -06:00
|
|
|
ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ),
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_ty_param_bound<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
bound: &'v TyParamBound) {
|
|
|
|
match *bound {
|
2014-12-24 00:38:10 -06:00
|
|
|
TraitTyParamBound(ref typ, ref modifier) => {
|
|
|
|
visitor.visit_poly_trait_ref(typ, modifier);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
|
|
|
RegionTyParamBound(ref lifetime) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_lifetime(lifetime);
|
2013-01-10 13:16:54 -06:00
|
|
|
}
|
2012-08-06 20:54:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) {
|
2015-09-28 06:26:26 -05:00
|
|
|
for param in &generics.ty_params {
|
2015-03-10 05:28:44 -05:00
|
|
|
visitor.visit_ident(param.span, param.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, ¶m.bounds);
|
|
|
|
walk_list!(visitor, visit_ty, ¶m.default);
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_lifetime_def, &generics.lifetimes);
|
2015-01-31 11:20:46 -06:00
|
|
|
for predicate in &generics.where_clause.predicates {
|
2015-11-17 08:24:49 -06:00
|
|
|
match *predicate {
|
|
|
|
WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty,
|
|
|
|
ref bounds,
|
|
|
|
ref bound_lifetimes,
|
|
|
|
..}) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(bounded_ty);
|
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
walk_list!(visitor, visit_lifetime_def, bound_lifetimes);
|
2014-11-28 22:08:30 -06:00
|
|
|
}
|
2015-11-17 08:24:49 -06:00
|
|
|
WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
|
|
|
|
ref bounds,
|
|
|
|
..}) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_lifetime(lifetime);
|
|
|
|
walk_list!(visitor, visit_lifetime, bounds);
|
2014-12-20 04:29:19 -06:00
|
|
|
}
|
2015-11-17 08:24:49 -06:00
|
|
|
WherePredicate::EqPredicate(WhereEqPredicate{id,
|
|
|
|
ref path,
|
|
|
|
ref ty,
|
|
|
|
..}) => {
|
2014-11-28 22:08:30 -06:00
|
|
|
visitor.visit_path(path, id);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
2014-11-28 22:08:30 -06:00
|
|
|
}
|
|
|
|
}
|
2014-08-11 11:32:26 -05:00
|
|
|
}
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
|
|
|
|
2015-09-28 16:23:54 -05:00
|
|
|
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) {
|
2016-02-08 08:04:11 -06:00
|
|
|
if let FunctionRetTy::Ty(ref output_ty) = *ret_ty {
|
2015-09-28 16:23:54 -05:00
|
|
|
visitor.visit_ty(output_ty)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) {
|
2015-01-31 11:20:46 -06:00
|
|
|
for argument in &function_declaration.inputs {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(&argument.pat);
|
|
|
|
visitor.visit_ty(&argument.ty)
|
|
|
|
}
|
2015-09-28 16:23:54 -05:00
|
|
|
walk_fn_ret_ty(visitor, &function_declaration.output)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2015-09-28 16:23:54 -05:00
|
|
|
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
function_kind: FnKind<'v>) {
|
2014-09-09 17:54:36 -05:00
|
|
|
match function_kind {
|
2015-08-26 05:00:14 -05:00
|
|
|
FnKind::ItemFn(_, generics, _, _, _, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-08-26 05:00:14 -05:00
|
|
|
FnKind::Method(_, sig, _) => {
|
2015-03-11 16:38:58 -05:00
|
|
|
visitor.visit_generics(&sig.generics);
|
|
|
|
visitor.visit_explicit_self(&sig.explicit_self);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
FnKind::Closure => {}
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2015-09-28 16:23:54 -05:00
|
|
|
}
|
2013-10-28 16:37:10 -05:00
|
|
|
|
2015-09-28 16:23:54 -05:00
|
|
|
pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
function_kind: FnKind<'v>,
|
|
|
|
function_declaration: &'v FnDecl,
|
|
|
|
function_body: &'v Block,
|
|
|
|
_span: Span) {
|
|
|
|
walk_fn_decl(visitor, function_declaration);
|
|
|
|
walk_fn_kind(visitor, function_kind);
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_block(function_body)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2015-03-10 05:28:44 -05:00
|
|
|
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) {
|
|
|
|
visitor.visit_ident(trait_item.span, trait_item.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &trait_item.attrs);
|
2015-03-10 05:28:44 -05:00
|
|
|
match trait_item.node {
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Const(ref ty, ref default) => {
|
2015-03-14 13:05:00 -05:00
|
|
|
visitor.visit_ty(ty);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, default);
|
2015-03-14 13:05:00 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Method(ref sig, None) => {
|
2015-03-11 01:38:27 -05:00
|
|
|
visitor.visit_explicit_self(&sig.explicit_self);
|
|
|
|
visitor.visit_generics(&sig.generics);
|
|
|
|
walk_fn_decl(visitor, &sig.decl);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Method(ref sig, Some(ref body)) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None), &sig.decl,
|
2015-03-11 16:38:58 -05:00
|
|
|
body, trait_item.span, trait_item.id);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2016-02-09 10:54:11 -06:00
|
|
|
TraitItemKind::Type(ref bounds, ref default) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty_param_bound, bounds);
|
|
|
|
walk_list!(visitor, visit_ty, default);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2015-03-10 05:28:44 -05:00
|
|
|
pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplItem) {
|
|
|
|
visitor.visit_ident(impl_item.span, impl_item.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &impl_item.attrs);
|
2015-03-10 05:28:44 -05:00
|
|
|
match impl_item.node {
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Const(ref ty, ref expr) => {
|
2015-03-14 13:05:00 -05:00
|
|
|
visitor.visit_ty(ty);
|
|
|
|
visitor.visit_expr(expr);
|
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Method(ref sig, ref body) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::Method(impl_item.ident, sig, Some(impl_item.vis)), &sig.decl,
|
2015-03-11 16:38:58 -05:00
|
|
|
body, impl_item.span, impl_item.id);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Type(ref ty) => {
|
2015-03-10 05:28:44 -05:00
|
|
|
visitor.visit_ty(ty);
|
2014-08-05 21:44:21 -05:00
|
|
|
}
|
2015-11-13 07:15:04 -06:00
|
|
|
ImplItemKind::Macro(ref mac) => {
|
2015-03-11 16:38:58 -05:00
|
|
|
visitor.visit_mac(mac);
|
|
|
|
}
|
2012-07-10 15:44:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
2015-10-07 19:20:57 -05:00
|
|
|
struct_definition: &'v VariantData) {
|
2015-10-08 15:45:46 -05:00
|
|
|
walk_list!(visitor, visit_struct_field, struct_definition.fields());
|
2012-08-07 17:54:59 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V,
|
|
|
|
struct_field: &'v StructField) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_opt_ident(visitor, struct_field.span, struct_field.node.ident());
|
|
|
|
visitor.visit_ty(&struct_field.node.ty);
|
|
|
|
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_stmt, &block.stmts);
|
|
|
|
walk_list!(visitor, visit_expr, &block.expr);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match statement.node {
|
2016-02-08 10:23:13 -06:00
|
|
|
StmtKind::Decl(ref declaration, _) => visitor.visit_decl(declaration),
|
|
|
|
StmtKind::Expr(ref expression, _) | StmtKind::Semi(ref expression, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 10:23:13 -06:00
|
|
|
StmtKind::Mac(ref mac, _, ref attrs) => {
|
2015-11-03 10:39:51 -06:00
|
|
|
visitor.visit_mac(mac);
|
2015-11-15 10:17:50 -06:00
|
|
|
for attr in attrs.as_attr_slice() {
|
2015-11-03 10:39:51 -06:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match declaration.node {
|
2016-02-08 08:34:47 -06:00
|
|
|
DeclKind::Local(ref local) => visitor.visit_local(local),
|
|
|
|
DeclKind::Item(ref item) => visitor.visit_item(item),
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
|
2013-07-19 20:42:11 -05:00
|
|
|
// Empty!
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match expression.node {
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Box(ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression)
|
2015-09-24 10:00:08 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::InPlace(ref place, ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(place);
|
|
|
|
visitor.visit_expr(subexpression)
|
2013-12-17 18:46:18 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Vec(ref subexpressions) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, subexpressions);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Repeat(ref element, ref count) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(element);
|
|
|
|
visitor.visit_expr(count)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Struct(ref path, ref fields, ref optional_base) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, expression.id);
|
2015-01-31 11:20:46 -06:00
|
|
|
for field in fields {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(field.ident.span, field.ident.node);
|
|
|
|
visitor.visit_expr(&field.expr)
|
2013-06-15 19:26:59 -05:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, optional_base);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Tup(ref subexpressions) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, subexpressions);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Call(ref callee_expression, ref arguments) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
|
|
|
visitor.visit_expr(callee_expression)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::MethodCall(ref ident, ref types, ref arguments) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ident(ident.span, ident.node);
|
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
|
|
|
walk_list!(visitor, visit_ty, types);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(left_expression);
|
|
|
|
visitor.visit_expr(right_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::AddrOf(_, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Lit(_) => {}
|
|
|
|
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_ty(typ)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(head_expression);
|
|
|
|
visitor.visit_block(if_block);
|
|
|
|
walk_list!(visitor, visit_expr, optional_else);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::While(ref subexpression, ref block, opt_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
|
|
|
walk_opt_ident(visitor, expression.span, opt_ident)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::IfLet(ref pattern, ref subexpression, ref if_block, ref optional_else) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(if_block);
|
|
|
|
walk_list!(visitor, visit_expr, optional_else);
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::WhileLet(ref pattern, ref subexpression, ref block, opt_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
|
|
|
walk_opt_ident(visitor, expression.span, opt_ident)
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::ForLoop(ref pattern, ref subexpression, ref block, opt_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
|
|
|
walk_opt_ident(visitor, expression.span, opt_ident)
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Loop(ref block, opt_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_block(block);
|
|
|
|
walk_opt_ident(visitor, expression.span, opt_ident)
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Match(ref subexpression, ref arms) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
walk_list!(visitor, visit_arm, arms);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Closure(_, ref function_declaration, ref body) => {
|
2015-08-26 05:00:14 -05:00
|
|
|
visitor.visit_fn(FnKind::Closure,
|
2015-09-28 06:26:26 -05:00
|
|
|
function_declaration,
|
|
|
|
body,
|
2014-05-29 00:26:56 -05:00
|
|
|
expression.span,
|
2014-09-12 05:10:30 -05:00
|
|
|
expression.id)
|
2014-05-29 00:26:56 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Block(ref block) => visitor.visit_block(block),
|
|
|
|
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(right_hand_expression);
|
|
|
|
visitor.visit_expr(left_hand_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(right_expression);
|
|
|
|
visitor.visit_expr(left_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Field(ref subexpression, ref ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_ident(ident.span, ident.node);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::TupField(ref subexpression, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
2014-08-09 22:54:33 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Index(ref main_expression, ref index_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(main_expression);
|
|
|
|
visitor.visit_expr(index_expression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-01-13 00:23:31 -06:00
|
|
|
ExprKind::Range(ref start, ref end, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, start);
|
|
|
|
walk_list!(visitor, visit_expr, end);
|
2014-12-12 23:41:02 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Path(ref maybe_qself, ref path) => {
|
2015-09-29 03:33:25 -05:00
|
|
|
if let Some(ref qself) = *maybe_qself {
|
2015-02-17 11:29:13 -06:00
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
}
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, expression.id)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Break(ref opt_sp_ident) | ExprKind::Again(ref opt_sp_ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
for sp_ident in opt_sp_ident {
|
|
|
|
visitor.visit_ident(sp_ident.span, sp_ident.node);
|
|
|
|
}
|
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Ret(ref optional_expression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, optional_expression);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Mac(ref mac) => visitor.visit_mac(mac),
|
|
|
|
ExprKind::Paren(ref subexpression) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::InlineAsm(ref ia) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
for &(_, ref input) in &ia.inputs {
|
|
|
|
visitor.visit_expr(&input)
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
2015-12-05 02:18:24 -06:00
|
|
|
for output in &ia.outputs {
|
|
|
|
visitor.visit_expr(&output.expr)
|
2013-03-12 19:53:25 -05:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2013-07-19 20:42:11 -05:00
|
|
|
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_expr_post(expression)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2014-09-09 17:54:36 -05:00
|
|
|
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) {
|
2015-09-28 06:26:26 -05:00
|
|
|
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);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|