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
|
2019-02-08 07:53:55 -06:00
|
|
|
//! execute before AST node B, then A is visited first. The borrow checker in
|
2014-06-09 15:12:30 -05:00
|
|
|
//! 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.
|
|
|
|
|
2019-02-06 11:33:01 -06:00
|
|
|
use crate::ast::*;
|
|
|
|
use crate::parse::token::Token;
|
|
|
|
use crate::tokenstream::{TokenTree, TokenStream};
|
|
|
|
|
2016-06-21 17:08:13 -05:00
|
|
|
use syntax_pos::Span;
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2018-03-20 17:58:25 -05:00
|
|
|
#[derive(Copy, Clone)]
|
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()
|
2019-02-23 12:39:27 -06:00
|
|
|
ItemFn(Ident, &'a FnHeader, &'a Visibility, &'a Block),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2014-06-09 15:12:30 -05:00
|
|
|
/// fn foo(&self)
|
2016-10-25 18:17:29 -05:00
|
|
|
Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a Block),
|
2013-03-13 21:25:28 -05:00
|
|
|
|
2016-10-25 18:17:29 -05:00
|
|
|
/// |x, y| body
|
|
|
|
Closure(&'a Expr),
|
2011-12-29 22:07:55 -06:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:15:43 -05:00
|
|
|
impl<'a> FnKind<'a> {
|
|
|
|
pub fn header(&self) -> Option<&'a FnHeader> {
|
|
|
|
match *self {
|
|
|
|
FnKind::ItemFn(_, header, _, _) => Some(header),
|
|
|
|
FnKind::Method(_, sig, _, _) => Some(&sig.header),
|
|
|
|
FnKind::Closure(_) => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-12 11:58:23 -05:00
|
|
|
/// Each method of the Visitor trait is a hook to be potentially
|
2019-02-08 07:53:55 -06: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;
|
2018-11-26 20:59:49 -06:00
|
|
|
/// e.g., the `visit_mod` method by default calls `visit::walk_mod`.
|
2014-05-12 11:58:23 -05:00
|
|
|
///
|
|
|
|
/// If you want to ensure that your code handles every variant
|
2019-02-08 07:53:55 -06:00
|
|
|
/// explicitly, you need to override each method. (And you also need
|
2014-05-12 11:58:23 -05:00
|
|
|
/// to monitor future changes to `Visitor` in case a new method with a
|
|
|
|
/// new default implementation gets introduced.)
|
2016-12-06 04:26:52 -06:00
|
|
|
pub trait Visitor<'ast>: Sized {
|
2014-11-18 10:39:16 -06:00
|
|
|
fn visit_name(&mut self, _span: Span, _name: Name) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
2018-03-18 19:54:56 -05:00
|
|
|
fn visit_ident(&mut self, ident: Ident) {
|
|
|
|
walk_ident(self, ident);
|
2013-11-22 06:24:49 -06:00
|
|
|
}
|
2017-05-11 14:15:29 -05:00
|
|
|
fn visit_mod(&mut self, m: &'ast Mod, _s: Span, _attrs: &[Attribute], _n: NodeId) {
|
|
|
|
walk_mod(self, m);
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_foreign_item(&mut self, i: &'ast ForeignItem) { walk_foreign_item(self, i) }
|
2017-03-15 21:27:40 -05:00
|
|
|
fn visit_global_asm(&mut self, ga: &'ast GlobalAsm) { walk_global_asm(self, ga) }
|
2016-12-06 04:26:52 -06:00
|
|
|
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) }
|
2018-05-17 13:28:50 -05:00
|
|
|
fn visit_anon_const(&mut self, c: &'ast AnonConst) { walk_anon_const(self, c) }
|
2016-12-06 04:26:52 -06:00
|
|
|
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) }
|
2018-05-27 14:07:09 -05:00
|
|
|
fn visit_generic_param(&mut self, param: &'ast GenericParam) {
|
2018-05-25 18:27:54 -05:00
|
|
|
walk_generic_param(self, param)
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_generics(&mut self, g: &'ast Generics) { walk_generics(self, g) }
|
2017-01-25 14:01:11 -06:00
|
|
|
fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
|
|
|
|
walk_where_predicate(self, p)
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_fn(&mut self, fk: FnKind<'ast>, fd: &'ast FnDecl, s: Span, _: NodeId) {
|
2016-10-25 18:17:29 -05:00
|
|
|
walk_fn(self, fk, fd, s)
|
2014-09-12 05:10:30 -05:00
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
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) }
|
2018-06-14 06:08:58 -05:00
|
|
|
fn visit_param_bound(&mut self, bounds: &'ast GenericBound) {
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_param_bound(self, bounds)
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef, m: &'ast TraitBoundModifier) {
|
2014-12-24 00:38:10 -06:00
|
|
|
walk_poly_trait_ref(self, t, m)
|
2014-11-07 05:53:45 -06:00
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_variant_data(&mut self, s: &'ast VariantData, _: Ident,
|
|
|
|
_: &'ast Generics, _: NodeId, _: Span) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_struct_def(self, s)
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
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) {
|
2015-10-02 08:14:20 -05:00
|
|
|
walk_enum_def(self, enum_definition, generics, item_id)
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_variant(&mut self, v: &'ast Variant, g: &'ast Generics, item_id: NodeId) {
|
2015-10-02 08:14:20 -05:00
|
|
|
walk_variant(self, v, g, item_id)
|
2015-06-22 21:55:57 -05:00
|
|
|
}
|
2018-01-15 16:44:32 -06:00
|
|
|
fn visit_label(&mut self, label: &'ast Label) {
|
|
|
|
walk_label(self, label)
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_lifetime(self, lifetime)
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_mac(&mut self, _mac: &'ast Mac) {
|
2014-10-09 14:17:22 -05:00
|
|
|
panic!("visit_mac disabled by default");
|
2018-11-26 20:59:49 -06:00
|
|
|
// N.B., see note about macros above.
|
2014-07-09 16:48:12 -05:00
|
|
|
// 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
|
|
|
}
|
2017-03-17 16:58:48 -05:00
|
|
|
fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) {
|
2017-05-12 01:05:52 -05:00
|
|
|
// Nothing to do
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_path(&mut self, path: &'ast Path, _id: NodeId) {
|
2014-09-12 05:10:30 -05:00
|
|
|
walk_path(self, path)
|
2013-12-08 13:25:35 -06:00
|
|
|
}
|
2017-09-26 16:04:00 -05:00
|
|
|
fn visit_use_tree(&mut self, use_tree: &'ast UseTree, id: NodeId, _nested: bool) {
|
|
|
|
walk_use_tree(self, use_tree, id)
|
2015-09-12 08:10:12 -05:00
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
|
2014-11-15 15:55:27 -06:00
|
|
|
walk_path_segment(self, path_span, path_segment)
|
|
|
|
}
|
2018-02-13 05:32:37 -06:00
|
|
|
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) {
|
|
|
|
walk_generic_args(self, path_span, generic_args)
|
|
|
|
}
|
2018-05-27 14:07:09 -05:00
|
|
|
fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) {
|
2018-05-16 06:57:45 -05:00
|
|
|
match generic_arg {
|
2018-05-27 14:07:09 -05:00
|
|
|
GenericArg::Lifetime(lt) => self.visit_lifetime(lt),
|
2018-05-27 15:54:10 -05:00
|
|
|
GenericArg::Type(ty) => self.visit_ty(ty),
|
2019-02-05 09:52:02 -06:00
|
|
|
GenericArg::Const(ct) => self.visit_anon_const(ct),
|
2018-02-13 05:32:37 -06:00
|
|
|
}
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_assoc_type_binding(&mut self, type_binding: &'ast TypeBinding) {
|
2014-12-28 09:07:21 -06:00
|
|
|
walk_assoc_type_binding(self, type_binding)
|
|
|
|
}
|
2017-10-23 03:22:28 -05:00
|
|
|
fn visit_attribute(&mut self, attr: &'ast Attribute) {
|
|
|
|
walk_attribute(self, attr)
|
|
|
|
}
|
|
|
|
fn visit_tt(&mut self, tt: TokenTree) {
|
|
|
|
walk_tt(self, tt)
|
|
|
|
}
|
|
|
|
fn visit_tts(&mut self, tts: TokenStream) {
|
|
|
|
walk_tts(self, tts)
|
|
|
|
}
|
|
|
|
fn visit_token(&mut self, _t: Token) {}
|
2017-10-25 19:28:25 -05:00
|
|
|
// FIXME: add `visit_interpolated` and `walk_interpolated`
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_vis(&mut self, vis: &'ast Visibility) {
|
2016-03-31 14:10:38 -05:00
|
|
|
walk_vis(self, vis)
|
|
|
|
}
|
2016-12-06 04:26:52 -06:00
|
|
|
fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FunctionRetTy) {
|
2016-08-01 07:15:54 -05:00
|
|
|
walk_fn_ret_ty(self, ret_ty)
|
|
|
|
}
|
2019-02-23 12:39:27 -06:00
|
|
|
fn visit_fn_header(&mut self, _header: &'ast FnHeader) {
|
|
|
|
// Nothing to do
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-03-18 19:54:56 -05:00
|
|
|
pub fn walk_ident<'a, V: Visitor<'a>>(visitor: &mut V, ident: Ident) {
|
|
|
|
visitor.visit_name(ident.span, ident.name);
|
2014-11-18 10:39:16 -06:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) {
|
2017-05-11 14:15:29 -05:00
|
|
|
visitor.visit_mod(&krate.module, krate.span, &krate.attrs, CRATE_NODE_ID);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &krate.attrs);
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_mod<'a, V: Visitor<'a>>(visitor: &mut V, module: &'a Mod) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_item, &module.items);
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) {
|
2016-06-17 23:01:57 -05:00
|
|
|
for attr in local.attrs.iter() {
|
2016-06-10 05:31:45 -05:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-01-15 16:44:32 -06:00
|
|
|
pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, label: &'a Label) {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(label.ident);
|
2018-01-15 16:44:32 -06:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(lifetime.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V,
|
|
|
|
trait_ref: &'a PolyTraitRef,
|
|
|
|
_: &TraitBoundModifier)
|
|
|
|
where V: Visitor<'a>,
|
2014-11-07 05:53:45 -06:00
|
|
|
{
|
2017-10-16 14:07:26 -05:00
|
|
|
walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params);
|
2014-11-07 05:53:45 -06:00
|
|
|
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) {
|
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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&item.vis);
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(item.ident);
|
2013-07-19 20:42:11 -05:00
|
|
|
match item.node {
|
2018-03-09 09:51:48 -06:00
|
|
|
ItemKind::ExternCrate(orig_name) => {
|
|
|
|
if let Some(orig_name) = orig_name {
|
|
|
|
visitor.visit_name(item.span, orig_name);
|
2018-01-15 16:44:32 -06:00
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
2017-09-26 16:04:00 -05:00
|
|
|
ItemKind::Use(ref use_tree) => {
|
|
|
|
visitor.visit_use_tree(use_tree, item.id, false)
|
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
|
|
|
}
|
2019-02-23 12:39:27 -06:00
|
|
|
ItemKind::Fn(ref declaration, ref header, ref generics, ref body) => {
|
2017-10-10 16:56:24 -05:00
|
|
|
visitor.visit_generics(generics);
|
2019-02-23 12:39:27 -06:00
|
|
|
visitor.visit_fn_header(header);
|
2018-06-06 17:50:59 -05:00
|
|
|
visitor.visit_fn(FnKind::ItemFn(item.ident, header,
|
2018-05-17 00:55:18 -05:00
|
|
|
&item.vis, body),
|
2015-09-28 06:26:26 -05:00
|
|
|
declaration,
|
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) => {
|
2017-05-11 14:15:29 -05:00
|
|
|
visitor.visit_mod(module, item.span, &item.attrs, 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
|
|
|
}
|
2017-03-15 21:27:40 -05:00
|
|
|
ItemKind::GlobalAsm(ref ga) => visitor.visit_global_asm(ga),
|
2019-03-28 19:28:07 -05:00
|
|
|
ItemKind::Ty(ref typ, ref generics) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(typ);
|
2019-03-28 19:28:07 -05:00
|
|
|
visitor.visit_generics(generics)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2019-03-28 19:28:07 -05:00
|
|
|
ItemKind::Existential(ref bounds, ref generics) => {
|
2018-07-03 12:38:14 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2019-03-28 19:28:07 -05:00
|
|
|
visitor.visit_generics(generics)
|
2018-07-03 12:38:14 -05:00
|
|
|
}
|
2019-03-28 19:28:07 -05:00
|
|
|
ItemKind::Enum(ref enum_definition, ref generics) => {
|
|
|
|
visitor.visit_generics(generics);
|
|
|
|
visitor.visit_enum_def(enum_definition, generics, item.id, item.span)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2016-11-18 10:14:42 -06:00
|
|
|
ItemKind::Impl(_, _, _,
|
2019-03-28 19:28:07 -05:00
|
|
|
ref generics,
|
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) => {
|
2019-03-28 19:28:07 -05:00
|
|
|
visitor.visit_generics(generics);
|
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-08-29 00:04:31 -05:00
|
|
|
ItemKind::Struct(ref struct_definition, ref generics) |
|
|
|
|
ItemKind::Union(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
|
|
|
}
|
2017-10-12 07:51:31 -05:00
|
|
|
ItemKind::Trait(.., ref generics, ref bounds, ref methods) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_generics(generics);
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_trait_item, methods);
|
2013-02-18 23:25:44 -06:00
|
|
|
}
|
2017-10-02 07:27:45 -05:00
|
|
|
ItemKind::TraitAlias(ref generics, ref bounds) => {
|
|
|
|
visitor.visit_generics(generics);
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2017-10-02 07:27:45 -05:00
|
|
|
}
|
2016-02-09 04:36:51 -06:00
|
|
|
ItemKind::Mac(ref mac) => visitor.visit_mac(mac),
|
2017-05-12 01:05:52 -05:00
|
|
|
ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id),
|
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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V,
|
|
|
|
enum_definition: &'a EnumDef,
|
|
|
|
generics: &'a Generics,
|
2016-06-12 02:51:31 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_variant<'a, V>(visitor: &mut V,
|
|
|
|
variant: &'a Variant,
|
|
|
|
generics: &'a Generics,
|
|
|
|
item_id: NodeId)
|
|
|
|
where V: Visitor<'a>,
|
2016-06-12 02:51:31 -05:00
|
|
|
{
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(variant.node.ident);
|
2018-03-18 17:21:30 -05:00
|
|
|
visitor.visit_variant_data(&variant.node.data, variant.node.ident,
|
2015-10-02 12:06:59 -05:00
|
|
|
generics, item_id, variant.span);
|
2018-05-17 13:28:50 -05:00
|
|
|
walk_list!(visitor, visit_anon_const, &variant.node.disr_expr);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
2015-01-02 05:55:31 -06:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match typ.node {
|
2016-09-20 09:54:24 -05:00
|
|
|
TyKind::Slice(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
|
|
|
}
|
2018-11-30 09:53:44 -06:00
|
|
|
TyKind::Never | TyKind::CVarArgs => {}
|
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) => {
|
2017-10-16 14:07:26 -05:00
|
|
|
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
|
2018-05-30 06:36:53 -05:00
|
|
|
walk_fn_decl(visitor, &function_declaration.decl);
|
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
|
|
|
}
|
2018-05-17 13:28:50 -05:00
|
|
|
TyKind::Array(ref ty, ref length) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_ty(ty);
|
2018-05-17 13:28:50 -05:00
|
|
|
visitor.visit_anon_const(length)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2017-10-10 09:33:19 -05:00
|
|
|
TyKind::TraitObject(ref bounds, ..) |
|
2018-06-18 09:23:13 -05:00
|
|
|
TyKind::ImplTrait(_, ref bounds) => {
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2016-07-31 20:25:32 -05:00
|
|
|
}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Typeof(ref expression) => {
|
2018-05-17 13:28:50 -05:00
|
|
|
visitor.visit_anon_const(expression)
|
2013-08-22 16:00:02 -05:00
|
|
|
}
|
2017-03-28 20:56:29 -05:00
|
|
|
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
|
2016-02-08 09:53:21 -06:00
|
|
|
TyKind::Mac(ref mac) => {
|
2015-07-25 23:30:35 -05:00
|
|
|
visitor.visit_mac(mac)
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a 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
|
|
|
|
2017-09-26 16:04:00 -05:00
|
|
|
pub fn walk_use_tree<'a, V: Visitor<'a>>(
|
|
|
|
visitor: &mut V, use_tree: &'a UseTree, id: NodeId,
|
|
|
|
) {
|
|
|
|
visitor.visit_path(&use_tree.prefix, id);
|
|
|
|
match use_tree.kind {
|
2018-06-13 11:44:06 -05:00
|
|
|
UseTreeKind::Simple(rename, ..) => {
|
|
|
|
// the extra IDs are handled during HIR lowering
|
2018-03-09 09:58:44 -06:00
|
|
|
if let Some(rename) = rename {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(rename);
|
2018-03-09 09:58:44 -06:00
|
|
|
}
|
2017-09-26 16:04:00 -05:00
|
|
|
}
|
|
|
|
UseTreeKind::Glob => {},
|
|
|
|
UseTreeKind::Nested(ref use_trees) => {
|
|
|
|
for &(ref nested_tree, nested_id) in use_trees {
|
|
|
|
visitor.visit_use_tree(nested_tree, nested_id, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-12 08:10:12 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V,
|
|
|
|
path_span: Span,
|
|
|
|
segment: &'a PathSegment) {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(segment.ident);
|
2018-02-23 11:48:54 -06:00
|
|
|
if let Some(ref args) = segment.args {
|
|
|
|
visitor.visit_generic_args(path_span, args);
|
2016-12-10 00:45:58 -06:00
|
|
|
}
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
|
|
|
|
2018-02-13 05:32:37 -06:00
|
|
|
pub fn walk_generic_args<'a, V>(visitor: &mut V,
|
|
|
|
_path_span: Span,
|
|
|
|
generic_args: &'a GenericArgs)
|
2016-12-06 04:26:52 -06:00
|
|
|
where V: Visitor<'a>,
|
2016-06-12 02:51:31 -05:00
|
|
|
{
|
2018-02-13 05:32:37 -06:00
|
|
|
match *generic_args {
|
|
|
|
GenericArgs::AngleBracketed(ref data) => {
|
2018-05-16 06:57:45 -05:00
|
|
|
walk_list!(visitor, visit_generic_arg, &data.args);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_assoc_type_binding, &data.bindings);
|
2014-11-15 15:55:27 -06:00
|
|
|
}
|
2018-02-13 05:32:37 -06:00
|
|
|
GenericArgs::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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_assoc_type_binding<'a, V: Visitor<'a>>(visitor: &mut V,
|
|
|
|
type_binding: &'a TypeBinding) {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match pattern.node {
|
2016-03-06 06:54:44 -06:00
|
|
|
PatKind::TupleStruct(ref path, ref children, _) => {
|
2014-09-12 05:10:30 -05:00
|
|
|
visitor.visit_path(path, pattern.id);
|
2016-03-06 06:54:44 -06:00
|
|
|
walk_list!(visitor, visit_pat, children);
|
2012-08-06 19:01:14 -05:00
|
|
|
}
|
2016-06-11 10:47:47 -05:00
|
|
|
PatKind::Path(ref opt_qself, ref path) => {
|
|
|
|
if let Some(ref qself) = *opt_qself {
|
|
|
|
visitor.visit_ty(&qself.ty);
|
|
|
|
}
|
2015-03-25 11:53:28 -05:00
|
|
|
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 {
|
2017-01-03 21:13:01 -06:00
|
|
|
walk_list!(visitor, visit_attribute, field.node.attrs.iter());
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(field.node.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(&field.node.pat)
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
|
|
|
}
|
2016-03-06 06:54:44 -06:00
|
|
|
PatKind::Tuple(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) |
|
2018-02-24 06:27:06 -06:00
|
|
|
PatKind::Ref(ref subpattern, _) |
|
|
|
|
PatKind::Paren(ref subpattern) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(subpattern)
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2018-03-18 08:47:09 -05:00
|
|
|
PatKind::Ident(_, ident, ref optional_subpattern) => {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(ident);
|
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),
|
2017-01-10 15:13:53 -06:00
|
|
|
PatKind::Range(ref lower_bound, ref upper_bound, _) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(lower_bound);
|
2017-01-10 15:13:53 -06:00
|
|
|
visitor.visit_expr(upper_bound);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2016-02-11 12:16:33 -06:00
|
|
|
PatKind::Wild => (),
|
2016-09-20 09:54:24 -05:00
|
|
|
PatKind::Slice(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, foreign_item: &'a ForeignItem) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&foreign_item.vis);
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(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),
|
2017-09-03 13:53:58 -05:00
|
|
|
ForeignItemKind::Ty => (),
|
2018-03-10 20:16:26 -06:00
|
|
|
ForeignItemKind::Macro(ref mac) => visitor.visit_mac(mac),
|
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
|
|
|
}
|
|
|
|
|
2017-03-15 21:27:40 -05:00
|
|
|
pub fn walk_global_asm<'a, V: Visitor<'a>>(_: &mut V, _: &'a GlobalAsm) {
|
|
|
|
// Empty!
|
|
|
|
}
|
|
|
|
|
2018-06-14 06:08:58 -05:00
|
|
|
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
|
2014-11-15 15:55:27 -06:00
|
|
|
match *bound {
|
2018-06-14 06:23:46 -05:00
|
|
|
GenericBound::Trait(ref typ, ref modifier) => visitor.visit_poly_trait_ref(typ, modifier),
|
|
|
|
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
|
2012-08-06 20:54:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-27 14:07:09 -05:00
|
|
|
pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) {
|
2018-05-28 07:33:28 -05:00
|
|
|
visitor.visit_ident(param.ident);
|
2018-06-15 04:52:46 -05:00
|
|
|
walk_list!(visitor, visit_attribute, param.attrs.iter());
|
2018-05-31 09:52:17 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, ¶m.bounds);
|
2018-05-26 13:16:21 -05:00
|
|
|
match param.kind {
|
2019-02-28 16:43:53 -06:00
|
|
|
GenericParamKind::Lifetime => (),
|
2018-05-31 09:52:17 -05:00
|
|
|
GenericParamKind::Type { ref default } => walk_list!(visitor, visit_ty, default),
|
2019-02-05 09:52:02 -06:00
|
|
|
GenericParamKind::Const { ref ty, .. } => visitor.visit_ty(ty),
|
2011-12-28 10:50:12 -06:00
|
|
|
}
|
2017-10-16 14:07:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) {
|
|
|
|
walk_list!(visitor, visit_generic_param, &generics.params);
|
2017-01-25 14:01:11 -06:00
|
|
|
walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) {
|
|
|
|
match *predicate {
|
|
|
|
WherePredicate::BoundPredicate(WhereBoundPredicate{ref bounded_ty,
|
|
|
|
ref bounds,
|
2017-10-16 14:07:26 -05:00
|
|
|
ref bound_generic_params,
|
2017-01-25 14:01:11 -06:00
|
|
|
..}) => {
|
|
|
|
visitor.visit_ty(bounded_ty);
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2017-10-16 14:07:26 -05:00
|
|
|
walk_list!(visitor, visit_generic_param, bound_generic_params);
|
2017-01-25 14:01:11 -06:00
|
|
|
}
|
|
|
|
WherePredicate::RegionPredicate(WhereRegionPredicate{ref lifetime,
|
|
|
|
ref bounds,
|
|
|
|
..}) => {
|
|
|
|
visitor.visit_lifetime(lifetime);
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2017-01-25 14:01:11 -06:00
|
|
|
}
|
|
|
|
WherePredicate::EqPredicate(WhereEqPredicate{ref lhs_ty,
|
|
|
|
ref rhs_ty,
|
|
|
|
..}) => {
|
|
|
|
visitor.visit_ty(lhs_ty);
|
|
|
|
visitor.visit_ty(rhs_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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &'a 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)
|
|
|
|
}
|
2016-08-01 07:15:54 -05:00
|
|
|
visitor.visit_fn_ret_ty(&function_declaration.output)
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl, _span: Span)
|
|
|
|
where V: Visitor<'a>,
|
2016-10-25 18:17:29 -05:00
|
|
|
{
|
|
|
|
match kind {
|
2019-02-23 12:39:27 -06:00
|
|
|
FnKind::ItemFn(_, header, _, body) => {
|
|
|
|
visitor.visit_fn_header(header);
|
2016-10-25 18:17:29 -05:00
|
|
|
walk_fn_decl(visitor, declaration);
|
|
|
|
visitor.visit_block(body);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
2019-02-23 12:39:27 -06:00
|
|
|
FnKind::Method(_, sig, _, body) => {
|
|
|
|
visitor.visit_fn_header(&sig.header);
|
2016-10-25 18:17:29 -05:00
|
|
|
walk_fn_decl(visitor, declaration);
|
|
|
|
visitor.visit_block(body);
|
|
|
|
}
|
|
|
|
FnKind::Closure(body) => {
|
|
|
|
walk_fn_decl(visitor, declaration);
|
|
|
|
visitor.visit_expr(body);
|
2013-10-28 16:37:10 -05:00
|
|
|
}
|
|
|
|
}
|
2015-09-28 16:23:54 -05:00
|
|
|
}
|
2013-10-28 16:37:10 -05:00
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a TraitItem) {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(trait_item.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &trait_item.attrs);
|
2017-09-21 21:18:47 -05:00
|
|
|
visitor.visit_generics(&trait_item.generics);
|
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) => {
|
2019-02-23 12:39:27 -06:00
|
|
|
visitor.visit_fn_header(&sig.header);
|
2015-03-11 01:38:27 -05:00
|
|
|
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)) => {
|
2016-10-25 18:17:29 -05:00
|
|
|
visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None, body),
|
|
|
|
&sig.decl, 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) => {
|
2018-05-28 09:23:16 -05:00
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_ty, default);
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2016-06-10 20:00:07 -05:00
|
|
|
TraitItemKind::Macro(ref mac) => {
|
|
|
|
visitor.visit_mac(mac);
|
|
|
|
}
|
2015-03-10 05:28:44 -05:00
|
|
|
}
|
2012-07-11 12:28:30 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplItem) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&impl_item.vis);
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(impl_item.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_attribute, &impl_item.attrs);
|
2017-09-21 21:18:47 -05:00
|
|
|
visitor.visit_generics(&impl_item.generics);
|
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) => {
|
2016-10-25 18:17:29 -05:00
|
|
|
visitor.visit_fn(FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), body),
|
|
|
|
&sig.decl, 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
|
|
|
}
|
2018-07-03 12:38:14 -05:00
|
|
|
ImplItemKind::Existential(ref bounds) => {
|
|
|
|
walk_list!(visitor, visit_param_bound, bounds);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_struct_def<'a, V: Visitor<'a>>(visitor: &mut V, struct_definition: &'a 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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_struct_field<'a, V: Visitor<'a>>(visitor: &mut V, struct_field: &'a StructField) {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_vis(&struct_field.vis);
|
2018-01-15 16:44:32 -06:00
|
|
|
if let Some(ident) = struct_field.ident {
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(ident);
|
2018-01-15 16:44:32 -06:00
|
|
|
}
|
2016-04-06 03:19:10 -05:00
|
|
|
visitor.visit_ty(&struct_field.ty);
|
|
|
|
walk_list!(visitor, visit_attribute, &struct_field.attrs);
|
2012-08-15 17:53:58 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_stmt, &block.stmts);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
|
2013-07-19 20:42:11 -05:00
|
|
|
match statement.node {
|
2016-06-16 21:30:01 -05:00
|
|
|
StmtKind::Local(ref local) => visitor.visit_local(local),
|
|
|
|
StmtKind::Item(ref item) => visitor.visit_item(item),
|
|
|
|
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-06-16 21:30:01 -05:00
|
|
|
StmtKind::Mac(ref mac) => {
|
|
|
|
let (ref mac, _, ref attrs) = **mac;
|
2015-11-03 10:39:51 -06:00
|
|
|
visitor.visit_mac(mac);
|
2016-06-17 23:01:57 -05:00
|
|
|
for attr in attrs.iter() {
|
2015-11-03 10:39:51 -06:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:37:00 -05:00
|
|
|
pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a Mac) {
|
|
|
|
visitor.visit_path(&mac.node.path, DUMMY_NODE_ID);
|
2011-07-08 18:35:09 -05:00
|
|
|
}
|
|
|
|
|
2018-05-17 13:28:50 -05:00
|
|
|
pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) {
|
|
|
|
visitor.visit_expr(&constant.value);
|
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
2016-06-17 23:01:57 -05:00
|
|
|
for attr in expression.attrs.iter() {
|
2016-06-10 05:31:45 -05:00
|
|
|
visitor.visit_attribute(attr);
|
|
|
|
}
|
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)
|
2018-05-24 16:34:09 -05:00
|
|
|
}
|
2017-01-16 01:36:10 -06:00
|
|
|
ExprKind::Array(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);
|
2018-05-17 13:28:50 -05:00
|
|
|
visitor.visit_anon_const(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 {
|
2017-01-03 21:13:01 -06:00
|
|
|
walk_list!(visitor, visit_attribute, field.attrs.iter());
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(field.ident);
|
2015-09-28 06:26:26 -05:00
|
|
|
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) => {
|
2016-09-17 18:14:09 -05:00
|
|
|
visitor.visit_expr(callee_expression);
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
2013-02-18 00:20:36 -06:00
|
|
|
}
|
2017-07-06 18:39:55 -05:00
|
|
|
ExprKind::MethodCall(ref segment, ref arguments) => {
|
|
|
|
visitor.visit_path_segment(expression.span, segment);
|
2016-09-17 18:14:09 -05:00
|
|
|
walk_list!(visitor, visit_expr, arguments);
|
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
|
|
|
}
|
2018-01-15 16:44:32 -06:00
|
|
|
ExprKind::While(ref subexpression, ref block, ref opt_label) => {
|
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2018-02-23 18:12:35 -06:00
|
|
|
ExprKind::IfLet(ref pats, ref subexpression, ref if_block, ref optional_else) => {
|
|
|
|
walk_list!(visitor, visit_pat, pats);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(if_block);
|
|
|
|
walk_list!(visitor, visit_expr, optional_else);
|
|
|
|
}
|
2018-02-23 18:12:35 -06:00
|
|
|
ExprKind::WhileLet(ref pats, ref subexpression, ref block, ref opt_label) => {
|
2018-01-15 16:44:32 -06:00
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
2018-02-23 18:12:35 -06:00
|
|
|
walk_list!(visitor, visit_pat, pats);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
|
|
|
}
|
2018-01-15 16:44:32 -06:00
|
|
|
ExprKind::ForLoop(ref pattern, ref subexpression, ref block, ref opt_label) => {
|
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_pat(pattern);
|
|
|
|
visitor.visit_expr(subexpression);
|
|
|
|
visitor.visit_block(block);
|
|
|
|
}
|
2018-01-15 16:44:32 -06:00
|
|
|
ExprKind::Loop(ref block, ref opt_label) => {
|
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_block(block);
|
|
|
|
}
|
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
|
|
|
}
|
2018-06-06 17:50:59 -05:00
|
|
|
ExprKind::Closure(_, _, _, ref function_declaration, ref body, _decl_span) => {
|
2016-10-25 18:17:29 -05:00
|
|
|
visitor.visit_fn(FnKind::Closure(body),
|
2015-09-28 06:26:26 -05:00
|
|
|
function_declaration,
|
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
|
|
|
}
|
2018-04-15 22:44:39 -05:00
|
|
|
ExprKind::Block(ref block, ref opt_label) => {
|
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
|
|
|
visitor.visit_block(block);
|
|
|
|
}
|
2018-06-06 17:50:59 -05:00
|
|
|
ExprKind::Async(_, _, ref body) => {
|
|
|
|
visitor.visit_block(body);
|
|
|
|
}
|
2019-04-18 14:55:23 -05:00
|
|
|
ExprKind::Await(_, ref expr) => visitor.visit_expr(expr),
|
2016-02-08 09:05:05 -06:00
|
|
|
ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => {
|
2016-09-17 18:14:09 -05:00
|
|
|
visitor.visit_expr(left_hand_expression);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(right_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) => {
|
2016-09-17 18:14:09 -05:00
|
|
|
visitor.visit_expr(left_expression);
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(right_expression);
|
2013-07-19 20:42:11 -05:00
|
|
|
}
|
2018-03-18 08:47:09 -05:00
|
|
|
ExprKind::Field(ref subexpression, ident) => {
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(subexpression);
|
2018-03-18 19:54:56 -05:00
|
|
|
visitor.visit_ident(ident);
|
2013-02-18 00:20:36 -06: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
|
|
|
}
|
2018-01-15 16:44:32 -06:00
|
|
|
ExprKind::Break(ref opt_label, ref opt_expr) => {
|
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
2016-10-29 17:15:06 -05:00
|
|
|
walk_list!(visitor, visit_expr, opt_expr);
|
|
|
|
}
|
2018-01-15 16:44:32 -06:00
|
|
|
ExprKind::Continue(ref opt_label) => {
|
|
|
|
walk_list!(visitor, visit_label, opt_label);
|
2015-09-28 06:26:26 -05:00
|
|
|
}
|
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 {
|
2017-05-12 13:05:39 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2016-12-26 07:34:03 -06:00
|
|
|
ExprKind::Yield(ref optional_expression) => {
|
|
|
|
walk_list!(visitor, visit_expr, optional_expression);
|
|
|
|
}
|
2016-02-28 16:38:48 -06:00
|
|
|
ExprKind::Try(ref subexpression) => {
|
|
|
|
visitor.visit_expr(subexpression)
|
|
|
|
}
|
2018-07-21 20:47:02 -05:00
|
|
|
ExprKind::TryBlock(ref body) => {
|
2017-02-17 17:12:47 -06:00
|
|
|
visitor.visit_block(body)
|
|
|
|
}
|
2018-12-16 19:57:32 -06:00
|
|
|
ExprKind::Err => {}
|
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
|
|
|
}
|
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
|
2015-09-28 06:26:26 -05:00
|
|
|
walk_list!(visitor, visit_pat, &arm.pats);
|
2018-08-29 23:18:11 -05:00
|
|
|
if let Some(ref g) = &arm.guard {
|
|
|
|
match g {
|
|
|
|
Guard::If(ref e) => visitor.visit_expr(e),
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 06:26:26 -05:00
|
|
|
visitor.visit_expr(&arm.body);
|
|
|
|
walk_list!(visitor, visit_attribute, &arm.attrs);
|
2011-06-08 15:48:19 -05:00
|
|
|
}
|
2016-03-31 14:10:38 -05:00
|
|
|
|
2016-12-06 04:26:52 -06:00
|
|
|
pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
|
2018-01-28 23:12:09 -06:00
|
|
|
if let VisibilityKind::Restricted { ref path, id } = vis.node {
|
2016-04-10 18:10:46 -05:00
|
|
|
visitor.visit_path(path, id);
|
2016-03-31 14:10:38 -05:00
|
|
|
}
|
|
|
|
}
|
2017-10-23 03:22:28 -05:00
|
|
|
|
|
|
|
pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) {
|
|
|
|
visitor.visit_tts(attr.tokens.clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_tt<'a, V: Visitor<'a>>(visitor: &mut V, tt: TokenTree) {
|
|
|
|
match tt {
|
|
|
|
TokenTree::Token(_, tok) => visitor.visit_token(tok),
|
2019-01-08 23:53:14 -06:00
|
|
|
TokenTree::Delimited(_, _, tts) => visitor.visit_tts(tts),
|
2017-10-23 03:22:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn walk_tts<'a, V: Visitor<'a>>(visitor: &mut V, tts: TokenStream) {
|
|
|
|
for tt in tts.trees() {
|
|
|
|
visitor.visit_tt(tt);
|
|
|
|
}
|
|
|
|
}
|