]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_ast/src/visit.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / compiler / rustc_ast / src / visit.rs
CommitLineData
1a4d82fc
JJ
1//! AST walker. Each overridden visit method has full control over what
2//! happens with its node, it can do its own traversal of the node's children,
3//! call `visit::walk_*` to apply the default traversal algorithm, or prevent
4//! deeper traversal by doing nothing.
5//!
6//! Note: it is an important invariant that the default visitor walks the body
7//! of a function in "execution order" (more concretely, reverse post-order
8//! with respect to the CFG implied by the AST), meaning that if AST node A may
9fa01778 9//! execute before AST node B, then A is visited first. The borrow checker in
1a4d82fc
JJ
10//! particular relies on this property.
11//!
12//! Note: walking an AST before macro expansion is probably a bad idea. For
13//! instance, a walker looking for item names in a module will miss all of
14//! those that are created by the expansion of a macro.
15
9fa01778 16use crate::ast::*;
9fa01778 17
064997fb 18use rustc_span::symbol::Ident;
dfeec247 19use rustc_span::Span;
1a4d82fc 20
94222f64 21#[derive(Copy, Clone, Debug, PartialEq)]
74b04a01
XL
22pub enum AssocCtxt {
23 Trait,
24 Impl,
25}
26
94222f64 27#[derive(Copy, Clone, Debug, PartialEq)]
74b04a01
XL
28pub enum FnCtxt {
29 Free,
30 Foreign,
31 Assoc(AssocCtxt),
32}
33
04454e1e
FG
34#[derive(Copy, Clone, Debug)]
35pub enum BoundKind {
36 /// Trait bounds in generics bounds and type/trait alias.
37 /// E.g., `<T: Bound>`, `type A: Bound`, or `where T: Bound`.
38 Bound,
39
40 /// Trait bounds in `impl` type.
41 /// E.g., `type Foo = impl Bound1 + Bound2 + Bound3`.
42 Impl,
43
44 /// Trait bounds in trait object type.
45 /// E.g., `dyn Bound1 + Bound2 + Bound3`.
46 TraitObject,
47
48 /// Super traits of a trait.
49 /// E.g., `trait A: B`
50 SuperTraits,
51}
52
94222f64 53#[derive(Copy, Clone, Debug)]
1a4d82fc 54pub enum FnKind<'a> {
74b04a01 55 /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`.
04454e1e 56 Fn(FnCtxt, Ident, &'a FnSig, &'a Visibility, &'a Generics, Option<&'a Block>),
1a4d82fc 57
e1599b0c 58 /// E.g., `|x, y| body`.
064997fb 59 Closure(&'a ClosureBinder, &'a FnDecl, &'a Expr),
1a4d82fc
JJ
60}
61
48663c56
XL
62impl<'a> FnKind<'a> {
63 pub fn header(&self) -> Option<&'a FnHeader> {
64 match *self {
04454e1e 65 FnKind::Fn(_, _, sig, _, _, _) => Some(&sig.header),
064997fb 66 FnKind::Closure(_, _, _) => None,
74b04a01
XL
67 }
68 }
69
3dfed10e
XL
70 pub fn ident(&self) -> Option<&Ident> {
71 match self {
72 FnKind::Fn(_, ident, ..) => Some(ident),
73 _ => None,
74 }
75 }
76
74b04a01
XL
77 pub fn decl(&self) -> &'a FnDecl {
78 match self {
04454e1e 79 FnKind::Fn(_, _, sig, _, _, _) => &sig.decl,
064997fb 80 FnKind::Closure(_, decl, _) => decl,
74b04a01
XL
81 }
82 }
83
84 pub fn ctxt(&self) -> Option<FnCtxt> {
85 match self {
86 FnKind::Fn(ctxt, ..) => Some(*ctxt),
87 FnKind::Closure(..) => None,
48663c56
XL
88 }
89 }
90}
91
923072b8
FG
92#[derive(Copy, Clone, Debug)]
93pub enum LifetimeCtxt {
94 /// Appears in a reference type.
95 Rptr,
96 /// Appears as a bound on a type or another lifetime.
97 Bound,
98 /// Appears as a generic argument.
99 GenericArg,
100}
101
e1599b0c 102/// Each method of the `Visitor` trait is a hook to be potentially
9fa01778 103/// overridden. Each method's default implementation recursively visits
1a4d82fc 104/// the substructure of the input via the corresponding `walk` method;
6a06907d 105/// e.g., the `visit_item` method by default calls `visit::walk_item`.
1a4d82fc
JJ
106///
107/// If you want to ensure that your code handles every variant
9fa01778 108/// explicitly, you need to override each method. (And you also need
1a4d82fc
JJ
109/// to monitor future changes to `Visitor` in case a new method with a
110/// new default implementation gets introduced.)
476ff2be 111pub trait Visitor<'ast>: Sized {
064997fb 112 fn visit_ident(&mut self, _ident: Ident) {}
dfeec247
XL
113 fn visit_foreign_item(&mut self, i: &'ast ForeignItem) {
114 walk_foreign_item(self, i)
115 }
dfeec247
XL
116 fn visit_item(&mut self, i: &'ast Item) {
117 walk_item(self, i)
118 }
119 fn visit_local(&mut self, l: &'ast Local) {
120 walk_local(self, l)
121 }
122 fn visit_block(&mut self, b: &'ast Block) {
123 walk_block(self, b)
124 }
125 fn visit_stmt(&mut self, s: &'ast Stmt) {
126 walk_stmt(self, s)
127 }
128 fn visit_param(&mut self, param: &'ast Param) {
129 walk_param(self, param)
130 }
131 fn visit_arm(&mut self, a: &'ast Arm) {
132 walk_arm(self, a)
133 }
134 fn visit_pat(&mut self, p: &'ast Pat) {
135 walk_pat(self, p)
136 }
137 fn visit_anon_const(&mut self, c: &'ast AnonConst) {
138 walk_anon_const(self, c)
139 }
140 fn visit_expr(&mut self, ex: &'ast Expr) {
141 walk_expr(self, ex)
142 }
2b03887a
FG
143 /// This method is a hack to workaround unstable of `stmt_expr_attributes`.
144 /// It can be removed once that feature is stabilized.
145 fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) {
146 self.visit_expr(ex)
147 }
dfeec247
XL
148 fn visit_expr_post(&mut self, _ex: &'ast Expr) {}
149 fn visit_ty(&mut self, t: &'ast Ty) {
150 walk_ty(self, t)
151 }
8faf50e0
XL
152 fn visit_generic_param(&mut self, param: &'ast GenericParam) {
153 walk_generic_param(self, param)
154 }
dfeec247
XL
155 fn visit_generics(&mut self, g: &'ast Generics) {
156 walk_generics(self, g)
157 }
064997fb
FG
158 fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) {
159 walk_closure_binder(self, b)
160 }
8bb4bdeb
XL
161 fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
162 walk_where_predicate(self, p)
163 }
f2b60f7d
FG
164 fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) {
165 walk_fn(self, fk)
476ff2be 166 }
74b04a01
XL
167 fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) {
168 walk_assoc_item(self, i, ctxt)
dfeec247
XL
169 }
170 fn visit_trait_ref(&mut self, t: &'ast TraitRef) {
171 walk_trait_ref(self, t)
172 }
04454e1e 173 fn visit_param_bound(&mut self, bounds: &'ast GenericBound, _ctxt: BoundKind) {
8faf50e0 174 walk_param_bound(self, bounds)
1a4d82fc 175 }
f2b60f7d
FG
176 fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) {
177 walk_poly_trait_ref(self, t)
1a4d82fc 178 }
e1599b0c 179 fn visit_variant_data(&mut self, s: &'ast VariantData) {
1a4d82fc
JJ
180 walk_struct_def(self, s)
181 }
6a06907d
XL
182 fn visit_field_def(&mut self, s: &'ast FieldDef) {
183 walk_field_def(self, s)
dfeec247 184 }
f2b60f7d
FG
185 fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef) {
186 walk_enum_def(self, enum_definition)
c1a9b12d 187 }
e1599b0c
XL
188 fn visit_variant(&mut self, v: &'ast Variant) {
189 walk_variant(self, v)
1a4d82fc 190 }
2c00a5a8
XL
191 fn visit_label(&mut self, label: &'ast Label) {
192 walk_label(self, label)
193 }
923072b8 194 fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) {
b039eaaf 195 walk_lifetime(self, lifetime)
1a4d82fc 196 }
29967ef6
XL
197 fn visit_mac_call(&mut self, mac: &'ast MacCall) {
198 walk_mac(self, mac)
1a4d82fc 199 }
7cac9316
XL
200 fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) {
201 // Nothing to do
202 }
476ff2be 203 fn visit_path(&mut self, path: &'ast Path, _id: NodeId) {
1a4d82fc
JJ
204 walk_path(self, path)
205 }
ff7c6d11
XL
206 fn visit_use_tree(&mut self, use_tree: &'ast UseTree, id: NodeId, _nested: bool) {
207 walk_use_tree(self, use_tree, id)
b039eaaf 208 }
f2b60f7d
FG
209 fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
210 walk_path_segment(self, path_segment)
1a4d82fc 211 }
f2b60f7d
FG
212 fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) {
213 walk_generic_args(self, generic_args)
8faf50e0
XL
214 }
215 fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) {
29967ef6 216 walk_generic_arg(self, generic_arg)
1a4d82fc 217 }
5099ac24
FG
218 fn visit_assoc_constraint(&mut self, constraint: &'ast AssocConstraint) {
219 walk_assoc_constraint(self, constraint)
1a4d82fc 220 }
abe05a73
XL
221 fn visit_attribute(&mut self, attr: &'ast Attribute) {
222 walk_attribute(self, attr)
223 }
476ff2be 224 fn visit_vis(&mut self, vis: &'ast Visibility) {
54a0048b
SL
225 walk_vis(self, vis)
226 }
74b04a01 227 fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) {
5bcae85e
SL
228 walk_fn_ret_ty(self, ret_ty)
229 }
532ac7d7
XL
230 fn visit_fn_header(&mut self, _header: &'ast FnHeader) {
231 // Nothing to do
232 }
6a06907d
XL
233 fn visit_expr_field(&mut self, f: &'ast ExprField) {
234 walk_expr_field(self, f)
e1599b0c 235 }
6a06907d
XL
236 fn visit_pat_field(&mut self, fp: &'ast PatField) {
237 walk_pat_field(self, fp)
e1599b0c 238 }
a2a8927a
XL
239 fn visit_crate(&mut self, krate: &'ast Crate) {
240 walk_crate(self, krate)
241 }
04454e1e
FG
242 fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) {
243 walk_inline_asm(self, asm)
244 }
245 fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
246 walk_inline_asm_sym(self, sym)
247 }
223e47cc
LB
248}
249
b039eaaf
SL
250#[macro_export]
251macro_rules! walk_list {
2b03887a
FG
252 ($visitor: expr, $method: ident, $list: expr $(, $($extra_args: expr),* )?) => {
253 {
254 #[cfg_attr(not(bootstrap), allow(for_loops_over_fallibles))]
255 for elem in $list {
256 $visitor.$method(elem $(, $($extra_args,)* )?)
257 }
b039eaaf 258 }
1a4d82fc
JJ
259 }
260}
261
476ff2be 262pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) {
6a06907d 263 walk_list!(visitor, visit_item, &krate.items);
b039eaaf 264 walk_list!(visitor, visit_attribute, &krate.attrs);
1a4d82fc
JJ
265}
266
476ff2be 267pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) {
3157f602
XL
268 for attr in local.attrs.iter() {
269 visitor.visit_attribute(attr);
270 }
b039eaaf
SL
271 visitor.visit_pat(&local.pat);
272 walk_list!(visitor, visit_ty, &local.ty);
94222f64
XL
273 if let Some((init, els)) = local.kind.init_else_opt() {
274 visitor.visit_expr(init);
275 walk_list!(visitor, visit_block, els);
276 }
b039eaaf
SL
277}
278
2c00a5a8 279pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, label: &'a Label) {
83c7162d 280 visitor.visit_ident(label.ident);
2c00a5a8
XL
281}
282
476ff2be 283pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) {
83c7162d 284 visitor.visit_ident(lifetime.ident);
b039eaaf
SL
285}
286
f2b60f7d
FG
287pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef)
288where
dfeec247 289 V: Visitor<'a>,
1a4d82fc 290{
ff7c6d11 291 walk_list!(visitor, visit_generic_param, &trait_ref.bound_generic_params);
1a4d82fc
JJ
292 visitor.visit_trait_ref(&trait_ref.trait_ref);
293}
294
476ff2be 295pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) {
1a4d82fc
JJ
296 visitor.visit_path(&trait_ref.path, trait_ref.ref_id)
297}
298
476ff2be 299pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
a7813a04 300 visitor.visit_vis(&item.vis);
83c7162d 301 visitor.visit_ident(item.ident);
e74abb32 302 match item.kind {
064997fb 303 ItemKind::ExternCrate(_) => {}
dfeec247 304 ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
74b04a01 305 ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(_, ref typ, ref expr) => {
b039eaaf 306 visitor.visit_ty(typ);
74b04a01 307 walk_list!(visitor, visit_expr, expr);
1a4d82fc 308 }
3c0e092e 309 ItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => {
04454e1e
FG
310 let kind =
311 FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
74b04a01 312 visitor.visit_fn(kind, item.span, item.id)
dfeec247 313 }
6a06907d
XL
314 ItemKind::Mod(_unsafety, ref mod_kind) => match mod_kind {
315 ModKind::Loaded(items, _inline, _inner_span) => {
316 walk_list!(visitor, visit_item, items)
317 }
318 ModKind::Unloaded => {}
319 },
7453a54e 320 ItemKind::ForeignMod(ref foreign_module) => {
b039eaaf 321 walk_list!(visitor, visit_foreign_item, &foreign_module.items);
223e47cc 322 }
923072b8 323 ItemKind::GlobalAsm(ref asm) => visitor.visit_inline_asm(asm),
5e7ed085 324 ItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => {
74b04a01 325 visitor.visit_generics(generics);
04454e1e 326 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
74b04a01 327 walk_list!(visitor, visit_ty, ty);
1a4d82fc 328 }
532ac7d7
XL
329 ItemKind::Enum(ref enum_definition, ref generics) => {
330 visitor.visit_generics(generics);
f2b60f7d 331 visitor.visit_enum_def(enum_definition)
1a4d82fc 332 }
3c0e092e 333 ItemKind::Impl(box Impl {
dfeec247 334 defaultness: _,
3c0e092e 335 unsafety: _,
dfeec247 336 ref generics,
3c0e092e
XL
337 constness: _,
338 polarity: _,
dfeec247
XL
339 ref of_trait,
340 ref self_ty,
341 ref items,
5869c6ff 342 }) => {
532ac7d7 343 visitor.visit_generics(generics);
dfeec247
XL
344 walk_list!(visitor, visit_trait_ref, of_trait);
345 visitor.visit_ty(self_ty);
74b04a01 346 walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
970d7e83 347 }
dfeec247
XL
348 ItemKind::Struct(ref struct_definition, ref generics)
349 | ItemKind::Union(ref struct_definition, ref generics) => {
1a4d82fc 350 visitor.visit_generics(generics);
e1599b0c 351 visitor.visit_variant_data(struct_definition);
1a4d82fc 352 }
3c0e092e
XL
353 ItemKind::Trait(box Trait {
354 unsafety: _,
355 is_auto: _,
356 ref generics,
357 ref bounds,
358 ref items,
359 }) => {
1a4d82fc 360 visitor.visit_generics(generics);
04454e1e 361 walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
74b04a01 362 walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
1a4d82fc 363 }
ff7c6d11
XL
364 ItemKind::TraitAlias(ref generics, ref bounds) => {
365 visitor.visit_generics(generics);
04454e1e 366 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
ff7c6d11 367 }
29967ef6 368 ItemKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
7cac9316 369 ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id),
1a4d82fc 370 }
b039eaaf 371 walk_list!(visitor, visit_attribute, &item.attrs);
223e47cc
LB
372}
373
f2b60f7d 374pub fn walk_enum_def<'a, V: Visitor<'a>>(visitor: &mut V, enum_definition: &'a EnumDef) {
e1599b0c 375 walk_list!(visitor, visit_variant, &enum_definition.variants);
1a4d82fc 376}
223e47cc 377
e1599b0c 378pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant)
dfeec247
XL
379where
380 V: Visitor<'a>,
3157f602 381{
e1599b0c 382 visitor.visit_ident(variant.ident);
60c5eb7d 383 visitor.visit_vis(&variant.vis);
e1599b0c
XL
384 visitor.visit_variant_data(&variant.data);
385 walk_list!(visitor, visit_anon_const, &variant.disr_expr);
386 walk_list!(visitor, visit_attribute, &variant.attrs);
387}
388
6a06907d 389pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) {
e1599b0c
XL
390 visitor.visit_expr(&f.expr);
391 visitor.visit_ident(f.ident);
392 walk_list!(visitor, visit_attribute, f.attrs.iter());
393}
394
6a06907d 395pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) {
e1599b0c
XL
396 visitor.visit_ident(fp.ident);
397 visitor.visit_pat(&fp.pat);
398 walk_list!(visitor, visit_attribute, fp.attrs.iter());
1a4d82fc
JJ
399}
400
476ff2be 401pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
e74abb32 402 match typ.kind {
dfeec247
XL
403 TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => visitor.visit_ty(ty),
404 TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
7453a54e 405 TyKind::Rptr(ref opt_lifetime, ref mutable_type) => {
923072b8 406 walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Rptr);
b039eaaf 407 visitor.visit_ty(&mutable_type.ty)
1a4d82fc 408 }
7453a54e 409 TyKind::Tup(ref tuple_element_types) => {
b039eaaf 410 walk_list!(visitor, visit_ty, tuple_element_types);
1a4d82fc 411 }
7453a54e 412 TyKind::BareFn(ref function_declaration) => {
ff7c6d11 413 walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
94b46f34 414 walk_fn_decl(visitor, &function_declaration.decl);
1a4d82fc 415 }
7453a54e 416 TyKind::Path(ref maybe_qself, ref path) => {
c34b1796
AL
417 if let Some(ref qself) = *maybe_qself {
418 visitor.visit_ty(&qself.ty);
419 }
420 visitor.visit_path(path, typ.id);
1a4d82fc 421 }
94b46f34 422 TyKind::Array(ref ty, ref length) => {
b039eaaf 423 visitor.visit_ty(ty);
94b46f34 424 visitor.visit_anon_const(length)
1a4d82fc 425 }
04454e1e
FG
426 TyKind::TraitObject(ref bounds, ..) => {
427 walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject);
428 }
429 TyKind::ImplTrait(_, ref bounds) => {
430 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
5bcae85e 431 }
dfeec247 432 TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
cc61c64b 433 TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
29967ef6 434 TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
dfeec247 435 TyKind::Never | TyKind::CVarArgs => {}
1a4d82fc
JJ
436 }
437}
438
476ff2be 439pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
85aaf69f 440 for segment in &path.segments {
f2b60f7d 441 visitor.visit_path_segment(segment);
1a4d82fc
JJ
442 }
443}
444
dfeec247 445pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) {
ff7c6d11 446 visitor.visit_path(&use_tree.prefix, id);
ff7c6d11 447 match use_tree.kind {
94b46f34 448 UseTreeKind::Simple(rename, ..) => {
e1599b0c 449 // The extra IDs are handled during HIR lowering.
0531ce1d 450 if let Some(rename) = rename {
83c7162d 451 visitor.visit_ident(rename);
0531ce1d 452 }
ff7c6d11 453 }
dfeec247 454 UseTreeKind::Glob => {}
ff7c6d11
XL
455 UseTreeKind::Nested(ref use_trees) => {
456 for &(ref nested_tree, nested_id) in use_trees {
457 visitor.visit_use_tree(nested_tree, nested_id, true);
458 }
459 }
460 }
b039eaaf
SL
461}
462
f2b60f7d 463pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) {
83c7162d 464 visitor.visit_ident(segment.ident);
8faf50e0 465 if let Some(ref args) = segment.args {
f2b60f7d 466 visitor.visit_generic_args(args);
32a655c1 467 }
1a4d82fc
JJ
468}
469
f2b60f7d 470pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs)
dfeec247
XL
471where
472 V: Visitor<'a>,
3157f602 473{
8faf50e0
XL
474 match *generic_args {
475 GenericArgs::AngleBracketed(ref data) => {
ba9703b0
XL
476 for arg in &data.args {
477 match arg {
478 AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a),
5099ac24 479 AngleBracketedArg::Constraint(c) => visitor.visit_assoc_constraint(c),
ba9703b0
XL
480 }
481 }
1a4d82fc 482 }
8faf50e0 483 GenericArgs::Parenthesized(ref data) => {
b039eaaf 484 walk_list!(visitor, visit_ty, &data.inputs);
dfeec247 485 walk_fn_ret_ty(visitor, &data.output);
1a4d82fc
JJ
486 }
487 }
488}
489
29967ef6
XL
490pub fn walk_generic_arg<'a, V>(visitor: &mut V, generic_arg: &'a GenericArg)
491where
492 V: Visitor<'a>,
493{
494 match generic_arg {
923072b8 495 GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
29967ef6
XL
496 GenericArg::Type(ty) => visitor.visit_ty(ty),
497 GenericArg::Const(ct) => visitor.visit_anon_const(ct),
498 }
499}
500
5099ac24 501pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) {
dc9dc135 502 visitor.visit_ident(constraint.ident);
fc512014 503 if let Some(ref gen_args) = constraint.gen_args {
f2b60f7d 504 visitor.visit_generic_args(gen_args);
fc512014 505 }
dc9dc135 506 match constraint.kind {
5099ac24
FG
507 AssocConstraintKind::Equality { ref term } => match term {
508 Term::Ty(ty) => visitor.visit_ty(ty),
509 Term::Const(c) => visitor.visit_anon_const(c),
510 },
511 AssocConstraintKind::Bound { ref bounds } => {
04454e1e 512 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
dc9dc135
XL
513 }
514 }
1a4d82fc
JJ
515}
516
476ff2be 517pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
e74abb32 518 match pattern.kind {
17df50a5
XL
519 PatKind::TupleStruct(ref opt_qself, ref path, ref elems) => {
520 if let Some(ref qself) = *opt_qself {
521 visitor.visit_ty(&qself.ty);
522 }
7453a54e 523 visitor.visit_path(path, pattern.id);
416331ca 524 walk_list!(visitor, visit_pat, elems);
7453a54e 525 }
3157f602
XL
526 PatKind::Path(ref opt_qself, ref path) => {
527 if let Some(ref qself) = *opt_qself {
528 visitor.visit_ty(&qself.ty);
529 }
d9579d0f
AL
530 visitor.visit_path(path, pattern.id)
531 }
17df50a5
XL
532 PatKind::Struct(ref opt_qself, ref path, ref fields, _) => {
533 if let Some(ref qself) = *opt_qself {
534 visitor.visit_ty(&qself.ty);
535 }
1a4d82fc 536 visitor.visit_path(path, pattern.id);
6a06907d 537 walk_list!(visitor, visit_pat_field, fields);
1a4d82fc 538 }
dfeec247
XL
539 PatKind::Box(ref subpattern)
540 | PatKind::Ref(ref subpattern, _)
541 | PatKind::Paren(ref subpattern) => visitor.visit_pat(subpattern),
83c7162d
XL
542 PatKind::Ident(_, ident, ref optional_subpattern) => {
543 visitor.visit_ident(ident);
b039eaaf 544 walk_list!(visitor, visit_pat, optional_subpattern);
223e47cc 545 }
7453a54e 546 PatKind::Lit(ref expression) => visitor.visit_expr(expression),
32a655c1 547 PatKind::Range(ref lower_bound, ref upper_bound, _) => {
dfeec247
XL
548 walk_list!(visitor, visit_expr, lower_bound);
549 walk_list!(visitor, visit_expr, upper_bound);
223e47cc 550 }
dfeec247
XL
551 PatKind::Wild | PatKind::Rest => {}
552 PatKind::Tuple(ref elems) | PatKind::Slice(ref elems) | PatKind::Or(ref elems) => {
416331ca 553 walk_list!(visitor, visit_pat, elems);
223e47cc 554 }
29967ef6 555 PatKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
1a4d82fc
JJ
556 }
557}
558
74b04a01
XL
559pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) {
560 let Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = *item;
561 visitor.visit_vis(vis);
562 visitor.visit_ident(ident);
563 walk_list!(visitor, visit_attribute, attrs);
564 match kind {
565 ForeignItemKind::Static(ty, _, expr) => {
566 visitor.visit_ty(ty);
567 walk_list!(visitor, visit_expr, expr);
568 }
3c0e092e 569 ForeignItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => {
04454e1e 570 let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
74b04a01
XL
571 visitor.visit_fn(kind, span, id);
572 }
5e7ed085 573 ForeignItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
74b04a01 574 visitor.visit_generics(generics);
04454e1e 575 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
74b04a01
XL
576 walk_list!(visitor, visit_ty, ty);
577 }
ba9703b0 578 ForeignItemKind::MacCall(mac) => {
29967ef6 579 visitor.visit_mac_call(mac);
1a4d82fc 580 }
223e47cc 581 }
1a4d82fc
JJ
582}
583
8faf50e0 584pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
1a4d82fc 585 match *bound {
f2b60f7d 586 GenericBound::Trait(ref typ, ref _modifier) => visitor.visit_poly_trait_ref(typ),
923072b8
FG
587 GenericBound::Outlives(ref lifetime) => {
588 visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound)
589 }
223e47cc
LB
590 }
591}
592
ff7c6d11 593pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a GenericParam) {
8faf50e0
XL
594 visitor.visit_ident(param.ident);
595 walk_list!(visitor, visit_attribute, param.attrs.iter());
04454e1e 596 walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound);
8faf50e0 597 match param.kind {
dc9dc135 598 GenericParamKind::Lifetime => (),
8faf50e0 599 GenericParamKind::Type { ref default } => walk_list!(visitor, visit_ty, default),
5869c6ff
XL
600 GenericParamKind::Const { ref ty, ref default, .. } => {
601 visitor.visit_ty(ty);
602 if let Some(default) = default {
603 visitor.visit_anon_const(default);
604 }
605 }
1a4d82fc 606 }
ff7c6d11
XL
607}
608
609pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) {
610 walk_list!(visitor, visit_generic_param, &generics.params);
8bb4bdeb
XL
611 walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates);
612}
613
064997fb
FG
614pub fn walk_closure_binder<'a, V: Visitor<'a>>(visitor: &mut V, binder: &'a ClosureBinder) {
615 match binder {
616 ClosureBinder::NotPresent => {}
617 ClosureBinder::For { generic_params, span: _ } => {
618 walk_list!(visitor, visit_generic_param, generic_params)
619 }
620 }
621}
622
8bb4bdeb
XL
623pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) {
624 match *predicate {
dfeec247
XL
625 WherePredicate::BoundPredicate(WhereBoundPredicate {
626 ref bounded_ty,
627 ref bounds,
628 ref bound_generic_params,
629 ..
630 }) => {
8bb4bdeb 631 visitor.visit_ty(bounded_ty);
04454e1e 632 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
ff7c6d11 633 walk_list!(visitor, visit_generic_param, bound_generic_params);
8bb4bdeb 634 }
dfeec247
XL
635 WherePredicate::RegionPredicate(WhereRegionPredicate {
636 ref lifetime, ref bounds, ..
637 }) => {
923072b8 638 visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound);
04454e1e 639 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
8bb4bdeb 640 }
dfeec247 641 WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. }) => {
8bb4bdeb
XL
642 visitor.visit_ty(lhs_ty);
643 visitor.visit_ty(rhs_ty);
223e47cc
LB
644 }
645 }
646}
647
74b04a01
XL
648pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) {
649 if let FnRetTy::Ty(ref output_ty) = *ret_ty {
b039eaaf 650 visitor.visit_ty(output_ty)
223e47cc
LB
651 }
652}
653
476ff2be 654pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &'a FnDecl) {
e1599b0c
XL
655 for param in &function_declaration.inputs {
656 visitor.visit_param(param);
223e47cc 657 }
416331ca 658 visitor.visit_fn_ret_ty(&function_declaration.output);
223e47cc
LB
659}
660
f2b60f7d 661pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) {
476ff2be 662 match kind {
04454e1e
FG
663 FnKind::Fn(_, _, sig, _, generics, body) => {
664 visitor.visit_generics(generics);
532ac7d7 665 visitor.visit_fn_header(&sig.header);
74b04a01
XL
666 walk_fn_decl(visitor, &sig.decl);
667 walk_list!(visitor, visit_block, body);
476ff2be 668 }
064997fb
FG
669 FnKind::Closure(binder, decl, body) => {
670 visitor.visit_closure_binder(binder);
74b04a01 671 walk_fn_decl(visitor, decl);
476ff2be 672 visitor.visit_expr(body);
1a4d82fc 673 }
1a4d82fc 674 }
b039eaaf 675}
1a4d82fc 676
74b04a01
XL
677pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) {
678 let Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = *item;
679 visitor.visit_vis(vis);
680 visitor.visit_ident(ident);
681 walk_list!(visitor, visit_attribute, attrs);
682 match kind {
683 AssocItemKind::Const(_, ty, expr) => {
d9579d0f 684 visitor.visit_ty(ty);
dfeec247 685 walk_list!(visitor, visit_expr, expr);
d9579d0f 686 }
3c0e092e 687 AssocItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => {
04454e1e 688 let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
74b04a01 689 visitor.visit_fn(kind, span, id);
c34b1796 690 }
2b03887a 691 AssocItemKind::Type(box TyAlias { generics, bounds, ty, .. }) => {
74b04a01 692 visitor.visit_generics(generics);
04454e1e 693 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
dfeec247 694 walk_list!(visitor, visit_ty, ty);
d9579d0f 695 }
ba9703b0 696 AssocItemKind::MacCall(mac) => {
29967ef6 697 visitor.visit_mac_call(mac);
1a4d82fc 698 }
223e47cc
LB
699 }
700}
701
476ff2be 702pub fn walk_struct_def<'a, V: Visitor<'a>>(visitor: &mut V, struct_definition: &'a VariantData) {
6a06907d 703 walk_list!(visitor, visit_field_def, struct_definition.fields());
223e47cc
LB
704}
705
6a06907d
XL
706pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) {
707 visitor.visit_vis(&field.vis);
708 if let Some(ident) = field.ident {
83c7162d 709 visitor.visit_ident(ident);
2c00a5a8 710 }
6a06907d
XL
711 visitor.visit_ty(&field.ty);
712 walk_list!(visitor, visit_attribute, &field.attrs);
223e47cc
LB
713}
714
476ff2be 715pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) {
b039eaaf 716 walk_list!(visitor, visit_stmt, &block.stmts);
223e47cc
LB
717}
718
476ff2be 719pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
e74abb32 720 match statement.kind {
3157f602
XL
721 StmtKind::Local(ref local) => visitor.visit_local(local),
722 StmtKind::Item(ref item) => visitor.visit_item(item),
74b04a01
XL
723 StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr),
724 StmtKind::Empty => {}
ba9703b0 725 StmtKind::MacCall(ref mac) => {
fc512014 726 let MacCallStmt { ref mac, style: _, ref attrs, tokens: _ } = **mac;
29967ef6 727 visitor.visit_mac_call(mac);
3157f602 728 for attr in attrs.iter() {
92a42be0
SL
729 visitor.visit_attribute(attr);
730 }
731 }
223e47cc
LB
732 }
733}
734
ba9703b0 735pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) {
e1599b0c 736 visitor.visit_path(&mac.path, DUMMY_NODE_ID);
223e47cc
LB
737}
738
94b46f34
XL
739pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) {
740 visitor.visit_expr(&constant.value);
741}
742
04454e1e 743pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) {
17df50a5
XL
744 for (op, _) in &asm.operands {
745 match op {
746 InlineAsmOperand::In { expr, .. }
94222f64 747 | InlineAsmOperand::Out { expr: Some(expr), .. }
04454e1e 748 | InlineAsmOperand::InOut { expr, .. } => visitor.visit_expr(expr),
94222f64 749 InlineAsmOperand::Out { expr: None, .. } => {}
17df50a5
XL
750 InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
751 visitor.visit_expr(in_expr);
752 if let Some(out_expr) = out_expr {
753 visitor.visit_expr(out_expr);
754 }
755 }
756 InlineAsmOperand::Const { anon_const, .. } => visitor.visit_anon_const(anon_const),
04454e1e 757 InlineAsmOperand::Sym { sym } => visitor.visit_inline_asm_sym(sym),
17df50a5
XL
758 }
759 }
760}
761
04454e1e
FG
762pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineAsmSym) {
763 if let Some(ref qself) = sym.qself {
764 visitor.visit_ty(&qself.ty);
765 }
766 visitor.visit_path(&sym.path, sym.id);
767}
768
476ff2be 769pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
e1599b0c
XL
770 walk_list!(visitor, visit_attribute, expression.attrs.iter());
771
e74abb32 772 match expression.kind {
dfeec247 773 ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
32a655c1 774 ExprKind::Array(ref subexpressions) => {
b039eaaf 775 walk_list!(visitor, visit_expr, subexpressions);
1a4d82fc 776 }
29967ef6 777 ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const),
7453a54e 778 ExprKind::Repeat(ref element, ref count) => {
b039eaaf 779 visitor.visit_expr(element);
94b46f34 780 visitor.visit_anon_const(count)
1a4d82fc 781 }
6a06907d 782 ExprKind::Struct(ref se) => {
17df50a5
XL
783 if let Some(ref qself) = se.qself {
784 visitor.visit_ty(&qself.ty);
785 }
6a06907d
XL
786 visitor.visit_path(&se.path, expression.id);
787 walk_list!(visitor, visit_expr_field, &se.fields);
788 match &se.rest {
29967ef6
XL
789 StructRest::Base(expr) => visitor.visit_expr(expr),
790 StructRest::Rest(_span) => {}
791 StructRest::None => {}
792 }
223e47cc 793 }
7453a54e 794 ExprKind::Tup(ref subexpressions) => {
b039eaaf 795 walk_list!(visitor, visit_expr, subexpressions);
223e47cc 796 }
7453a54e 797 ExprKind::Call(ref callee_expression, ref arguments) => {
9e0c209e 798 visitor.visit_expr(callee_expression);
b039eaaf 799 walk_list!(visitor, visit_expr, arguments);
1a4d82fc 800 }
2b03887a 801 ExprKind::MethodCall(ref segment, ref receiver, ref arguments, _span) => {
f2b60f7d 802 visitor.visit_path_segment(segment);
2b03887a 803 visitor.visit_expr(receiver);
9e0c209e 804 walk_list!(visitor, visit_expr, arguments);
223e47cc 805 }
7453a54e 806 ExprKind::Binary(_, ref left_expression, ref right_expression) => {
b039eaaf
SL
807 visitor.visit_expr(left_expression);
808 visitor.visit_expr(right_expression)
1a4d82fc 809 }
60c5eb7d 810 ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
b039eaaf 811 visitor.visit_expr(subexpression)
1a4d82fc 812 }
7453a54e 813 ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
b039eaaf
SL
814 visitor.visit_expr(subexpression);
815 visitor.visit_ty(typ)
1a4d82fc 816 }
94222f64 817 ExprKind::Let(ref pat, ref expr, _) => {
e1599b0c 818 visitor.visit_pat(pat);
94222f64 819 visitor.visit_expr(expr);
dc9dc135 820 }
7453a54e 821 ExprKind::If(ref head_expression, ref if_block, ref optional_else) => {
b039eaaf
SL
822 visitor.visit_expr(head_expression);
823 visitor.visit_block(if_block);
824 walk_list!(visitor, visit_expr, optional_else);
1a4d82fc 825 }
2c00a5a8
XL
826 ExprKind::While(ref subexpression, ref block, ref opt_label) => {
827 walk_list!(visitor, visit_label, opt_label);
b039eaaf
SL
828 visitor.visit_expr(subexpression);
829 visitor.visit_block(block);
1a4d82fc 830 }
2c00a5a8
XL
831 ExprKind::ForLoop(ref pattern, ref subexpression, ref block, ref opt_label) => {
832 walk_list!(visitor, visit_label, opt_label);
b039eaaf
SL
833 visitor.visit_pat(pattern);
834 visitor.visit_expr(subexpression);
835 visitor.visit_block(block);
b039eaaf 836 }
2c00a5a8
XL
837 ExprKind::Loop(ref block, ref opt_label) => {
838 walk_list!(visitor, visit_label, opt_label);
b039eaaf 839 visitor.visit_block(block);
b039eaaf 840 }
7453a54e 841 ExprKind::Match(ref subexpression, ref arms) => {
b039eaaf
SL
842 visitor.visit_expr(subexpression);
843 walk_list!(visitor, visit_arm, arms);
223e47cc 844 }
064997fb
FG
845 ExprKind::Closure(ref binder, _, _, _, ref decl, ref body, _decl_span) => {
846 visitor.visit_fn(FnKind::Closure(binder, decl, body), expression.span, expression.id)
74b04a01 847 }
94b46f34
XL
848 ExprKind::Block(ref block, ref opt_label) => {
849 walk_list!(visitor, visit_label, opt_label);
850 visitor.visit_block(block);
851 }
8faf50e0
XL
852 ExprKind::Async(_, _, ref body) => {
853 visitor.visit_block(body);
854 }
416331ca 855 ExprKind::Await(ref expr) => visitor.visit_expr(expr),
dfeec247
XL
856 ExprKind::Assign(ref lhs, ref rhs, _) => {
857 visitor.visit_expr(lhs);
858 visitor.visit_expr(rhs);
1a4d82fc 859 }
7453a54e 860 ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
9e0c209e 861 visitor.visit_expr(left_expression);
b039eaaf 862 visitor.visit_expr(right_expression);
223e47cc 863 }
83c7162d 864 ExprKind::Field(ref subexpression, ident) => {
b039eaaf 865 visitor.visit_expr(subexpression);
83c7162d 866 visitor.visit_ident(ident);
223e47cc 867 }
7453a54e 868 ExprKind::Index(ref main_expression, ref index_expression) => {
b039eaaf
SL
869 visitor.visit_expr(main_expression);
870 visitor.visit_expr(index_expression)
223e47cc 871 }
54a0048b 872 ExprKind::Range(ref start, ref end, _) => {
b039eaaf
SL
873 walk_list!(visitor, visit_expr, start);
874 walk_list!(visitor, visit_expr, end);
223e47cc 875 }
fc512014 876 ExprKind::Underscore => {}
7453a54e 877 ExprKind::Path(ref maybe_qself, ref path) => {
c34b1796
AL
878 if let Some(ref qself) = *maybe_qself {
879 visitor.visit_ty(&qself.ty);
880 }
1a4d82fc 881 visitor.visit_path(path, expression.id)
223e47cc 882 }
2c00a5a8
XL
883 ExprKind::Break(ref opt_label, ref opt_expr) => {
884 walk_list!(visitor, visit_label, opt_label);
476ff2be
SL
885 walk_list!(visitor, visit_expr, opt_expr);
886 }
2c00a5a8
XL
887 ExprKind::Continue(ref opt_label) => {
888 walk_list!(visitor, visit_label, opt_label);
b039eaaf 889 }
7453a54e 890 ExprKind::Ret(ref optional_expression) => {
b039eaaf 891 walk_list!(visitor, visit_expr, optional_expression);
1a4d82fc 892 }
04454e1e
FG
893 ExprKind::Yeet(ref optional_expression) => {
894 walk_list!(visitor, visit_expr, optional_expression);
895 }
29967ef6 896 ExprKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
dfeec247 897 ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression),
923072b8 898 ExprKind::InlineAsm(ref asm) => visitor.visit_inline_asm(asm),
ea8adc8c
XL
899 ExprKind::Yield(ref optional_expression) => {
900 walk_list!(visitor, visit_expr, optional_expression);
901 }
dfeec247
XL
902 ExprKind::Try(ref subexpression) => visitor.visit_expr(subexpression),
903 ExprKind::TryBlock(ref body) => visitor.visit_block(body),
dc9dc135 904 ExprKind::Lit(_) | ExprKind::Err => {}
1a4d82fc
JJ
905 }
906
907 visitor.visit_expr_post(expression)
908}
909
e1599b0c
XL
910pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) {
911 walk_list!(visitor, visit_attribute, param.attrs.iter());
912 visitor.visit_pat(&param.pat);
913 visitor.visit_ty(&param.ty);
416331ca
XL
914}
915
476ff2be 916pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
e1599b0c 917 visitor.visit_pat(&arm.pat);
e1599b0c 918 walk_list!(visitor, visit_expr, &arm.guard);
b039eaaf
SL
919 visitor.visit_expr(&arm.body);
920 walk_list!(visitor, visit_attribute, &arm.attrs);
223e47cc 921}
54a0048b 922
476ff2be 923pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
f2b60f7d 924 if let VisibilityKind::Restricted { ref path, id, shorthand: _ } = vis.kind {
a7813a04 925 visitor.visit_path(path, id);
54a0048b
SL
926 }
927}
abe05a73
XL
928
929pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) {
60c5eb7d 930 match attr.kind {
f2b60f7d 931 AttrKind::Normal(ref normal) => walk_mac_args(visitor, &normal.item.args),
3dfed10e 932 AttrKind::DocComment(..) => {}
60c5eb7d
XL
933 }
934}
935
936pub fn walk_mac_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a MacArgs) {
937 match args {
938 MacArgs::Empty => {}
29967ef6 939 MacArgs::Delimited(_dspan, _delim, _tokens) => {}
04454e1e
FG
940 MacArgs::Eq(_eq_span, MacArgsEq::Ast(expr)) => visitor.visit_expr(expr),
941 MacArgs::Eq(_, MacArgsEq::Hir(lit)) => {
942 unreachable!("in literal form when walking mac args eq: {:?}", lit)
943 }
abe05a73
XL
944 }
945}