1pub use rustc_ast_ir::visit::VisitorResult;
17pub use rustc_ast_ir::{try_visit, visit_opt, walk_list, walk_visitable_list};
18use rustc_span::{Ident, Span};
19
20use crate::ast::*;
21use crate::ptr::P;
22
23#[derive(Copy, Clone, Debug, PartialEq)]
24pub enum AssocCtxt {
25 Trait,
26 Impl,
27}
28
29#[derive(Copy, Clone, Debug, PartialEq)]
30pub enum FnCtxt {
31 Free,
32 Foreign,
33 Assoc(AssocCtxt),
34}
35
36#[derive(Copy, Clone, Debug)]
37pub enum BoundKind {
38 Bound,
41
42 Impl,
45
46 TraitObject,
49
50 SuperTraits,
53}
54impl BoundKind {
55 pub fn descr(self) -> &'static str {
56 match self {
57 BoundKind::Bound => "bounds",
58 BoundKind::Impl => "`impl Trait`",
59 BoundKind::TraitObject => "`dyn` trait object bounds",
60 BoundKind::SuperTraits => "supertrait bounds",
61 }
62 }
63}
64
65#[derive(Copy, Clone, Debug)]
66pub enum FnKind<'a> {
67 Fn(FnCtxt, &'a Ident, &'a Visibility, &'a Fn),
69
70 Closure(&'a ClosureBinder, &'a Option<CoroutineKind>, &'a FnDecl, &'a Expr),
72}
73
74impl<'a> FnKind<'a> {
75 pub fn header(&self) -> Option<&'a FnHeader> {
76 match *self {
77 FnKind::Fn(_, _, _, Fn { sig, .. }) => Some(&sig.header),
78 FnKind::Closure(..) => None,
79 }
80 }
81
82 pub fn ident(&self) -> Option<&Ident> {
83 match self {
84 FnKind::Fn(_, ident, ..) => Some(ident),
85 _ => None,
86 }
87 }
88
89 pub fn decl(&self) -> &'a FnDecl {
90 match self {
91 FnKind::Fn(_, _, _, Fn { sig, .. }) => &sig.decl,
92 FnKind::Closure(_, _, decl, _) => decl,
93 }
94 }
95
96 pub fn ctxt(&self) -> Option<FnCtxt> {
97 match self {
98 FnKind::Fn(ctxt, ..) => Some(*ctxt),
99 FnKind::Closure(..) => None,
100 }
101 }
102}
103
104#[derive(Copy, Clone, Debug)]
105pub enum LifetimeCtxt {
106 Ref,
108 Bound,
110 GenericArg,
112}
113
114pub trait WalkItemKind {
115 type Ctxt;
116 fn walk<'a, V: Visitor<'a>>(
117 &'a self,
118 span: Span,
119 id: NodeId,
120 ident: &'a Ident,
121 visibility: &'a Visibility,
122 ctxt: Self::Ctxt,
123 visitor: &mut V,
124 ) -> V::Result;
125}
126
127pub trait Visitor<'ast>: Sized {
137 type Result: VisitorResult = ();
140
141 fn visit_ident(&mut self, _ident: &'ast Ident) -> Self::Result {
142 Self::Result::output()
143 }
144 fn visit_foreign_item(&mut self, i: &'ast ForeignItem) -> Self::Result {
145 walk_item(self, i)
146 }
147 fn visit_item(&mut self, i: &'ast Item) -> Self::Result {
148 walk_item(self, i)
149 }
150 fn visit_local(&mut self, l: &'ast Local) -> Self::Result {
151 walk_local(self, l)
152 }
153 fn visit_block(&mut self, b: &'ast Block) -> Self::Result {
154 walk_block(self, b)
155 }
156 fn visit_stmt(&mut self, s: &'ast Stmt) -> Self::Result {
157 walk_stmt(self, s)
158 }
159 fn visit_param(&mut self, param: &'ast Param) -> Self::Result {
160 walk_param(self, param)
161 }
162 fn visit_arm(&mut self, a: &'ast Arm) -> Self::Result {
163 walk_arm(self, a)
164 }
165 fn visit_pat(&mut self, p: &'ast Pat) -> Self::Result {
166 walk_pat(self, p)
167 }
168 fn visit_anon_const(&mut self, c: &'ast AnonConst) -> Self::Result {
169 walk_anon_const(self, c)
170 }
171 fn visit_expr(&mut self, ex: &'ast Expr) -> Self::Result {
172 walk_expr(self, ex)
173 }
174 fn visit_method_receiver_expr(&mut self, ex: &'ast Expr) -> Self::Result {
177 self.visit_expr(ex)
178 }
179 fn visit_ty(&mut self, t: &'ast Ty) -> Self::Result {
180 walk_ty(self, t)
181 }
182 fn visit_ty_pat(&mut self, t: &'ast TyPat) -> Self::Result {
183 walk_ty_pat(self, t)
184 }
185 fn visit_generic_param(&mut self, param: &'ast GenericParam) -> Self::Result {
186 walk_generic_param(self, param)
187 }
188 fn visit_generics(&mut self, g: &'ast Generics) -> Self::Result {
189 walk_generics(self, g)
190 }
191 fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) -> Self::Result {
192 walk_closure_binder(self, b)
193 }
194 fn visit_contract(&mut self, c: &'ast FnContract) -> Self::Result {
195 walk_contract(self, c)
196 }
197 fn visit_where_predicate(&mut self, p: &'ast WherePredicate) -> Self::Result {
198 walk_where_predicate(self, p)
199 }
200 fn visit_where_predicate_kind(&mut self, k: &'ast WherePredicateKind) -> Self::Result {
201 walk_where_predicate_kind(self, k)
202 }
203 fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) -> Self::Result {
204 walk_fn(self, fk)
205 }
206 fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) -> Self::Result {
207 walk_assoc_item(self, i, ctxt)
208 }
209 fn visit_trait_ref(&mut self, t: &'ast TraitRef) -> Self::Result {
210 walk_trait_ref(self, t)
211 }
212 fn visit_param_bound(&mut self, bounds: &'ast GenericBound, _ctxt: BoundKind) -> Self::Result {
213 walk_param_bound(self, bounds)
214 }
215 fn visit_precise_capturing_arg(&mut self, arg: &'ast PreciseCapturingArg) -> Self::Result {
216 walk_precise_capturing_arg(self, arg)
217 }
218 fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) -> Self::Result {
219 walk_poly_trait_ref(self, t)
220 }
221 fn visit_variant_data(&mut self, s: &'ast VariantData) -> Self::Result {
222 walk_struct_def(self, s)
223 }
224 fn visit_field_def(&mut self, s: &'ast FieldDef) -> Self::Result {
225 walk_field_def(self, s)
226 }
227 fn visit_enum_def(&mut self, enum_definition: &'ast EnumDef) -> Self::Result {
228 walk_enum_def(self, enum_definition)
229 }
230 fn visit_variant(&mut self, v: &'ast Variant) -> Self::Result {
231 walk_variant(self, v)
232 }
233 fn visit_variant_discr(&mut self, discr: &'ast AnonConst) -> Self::Result {
234 self.visit_anon_const(discr)
235 }
236 fn visit_label(&mut self, label: &'ast Label) -> Self::Result {
237 walk_label(self, label)
238 }
239 fn visit_lifetime(&mut self, lifetime: &'ast Lifetime, _: LifetimeCtxt) -> Self::Result {
240 walk_lifetime(self, lifetime)
241 }
242 fn visit_mac_call(&mut self, mac: &'ast MacCall) -> Self::Result {
243 walk_mac(self, mac)
244 }
245 fn visit_mac_def(&mut self, _mac: &'ast MacroDef, _id: NodeId) -> Self::Result {
246 Self::Result::output()
247 }
248 fn visit_path(&mut self, path: &'ast Path, _id: NodeId) -> Self::Result {
249 walk_path(self, path)
250 }
251 fn visit_use_tree(
252 &mut self,
253 use_tree: &'ast UseTree,
254 id: NodeId,
255 _nested: bool,
256 ) -> Self::Result {
257 walk_use_tree(self, use_tree, id)
258 }
259 fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) -> Self::Result {
260 walk_path_segment(self, path_segment)
261 }
262 fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) -> Self::Result {
263 walk_generic_args(self, generic_args)
264 }
265 fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) -> Self::Result {
266 walk_generic_arg(self, generic_arg)
267 }
268 fn visit_assoc_item_constraint(
269 &mut self,
270 constraint: &'ast AssocItemConstraint,
271 ) -> Self::Result {
272 walk_assoc_item_constraint(self, constraint)
273 }
274 fn visit_attribute(&mut self, attr: &'ast Attribute) -> Self::Result {
275 walk_attribute(self, attr)
276 }
277 fn visit_vis(&mut self, vis: &'ast Visibility) -> Self::Result {
278 walk_vis(self, vis)
279 }
280 fn visit_fn_ret_ty(&mut self, ret_ty: &'ast FnRetTy) -> Self::Result {
281 walk_fn_ret_ty(self, ret_ty)
282 }
283 fn visit_fn_header(&mut self, header: &'ast FnHeader) -> Self::Result {
284 walk_fn_header(self, header)
285 }
286 fn visit_expr_field(&mut self, f: &'ast ExprField) -> Self::Result {
287 walk_expr_field(self, f)
288 }
289 fn visit_pat_field(&mut self, fp: &'ast PatField) -> Self::Result {
290 walk_pat_field(self, fp)
291 }
292 fn visit_crate(&mut self, krate: &'ast Crate) -> Self::Result {
293 walk_crate(self, krate)
294 }
295 fn visit_inline_asm(&mut self, asm: &'ast InlineAsm) -> Self::Result {
296 walk_inline_asm(self, asm)
297 }
298 fn visit_format_args(&mut self, fmt: &'ast FormatArgs) -> Self::Result {
299 walk_format_args(self, fmt)
300 }
301 fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) -> Self::Result {
302 walk_inline_asm_sym(self, sym)
303 }
304 fn visit_capture_by(&mut self, _capture_by: &'ast CaptureBy) -> Self::Result {
305 Self::Result::output()
306 }
307 fn visit_coroutine_kind(&mut self, _coroutine_kind: &'ast CoroutineKind) -> Self::Result {
308 Self::Result::output()
309 }
310 fn visit_fn_decl(&mut self, fn_decl: &'ast FnDecl) -> Self::Result {
311 walk_fn_decl(self, fn_decl)
312 }
313 fn visit_qself(&mut self, qs: &'ast Option<P<QSelf>>) -> Self::Result {
314 walk_qself(self, qs)
315 }
316}
317
318pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::Result {
319 let Crate { attrs, items, spans: _, id: _, is_placeholder: _ } = krate;
320 walk_list!(visitor, visit_attribute, attrs);
321 walk_list!(visitor, visit_item, items);
322 V::Result::output()
323}
324
325pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::Result {
326 let Local { id: _, pat, ty, kind, span: _, colon_sp: _, attrs, tokens: _ } = local;
327 walk_list!(visitor, visit_attribute, attrs);
328 try_visit!(visitor.visit_pat(pat));
329 visit_opt!(visitor, visit_ty, ty);
330 if let Some((init, els)) = kind.init_else_opt() {
331 try_visit!(visitor.visit_expr(init));
332 visit_opt!(visitor, visit_block, els);
333 }
334 V::Result::output()
335}
336
337pub fn walk_label<'a, V: Visitor<'a>>(visitor: &mut V, Label { ident }: &'a Label) -> V::Result {
338 visitor.visit_ident(ident)
339}
340
341pub fn walk_lifetime<'a, V: Visitor<'a>>(visitor: &mut V, lifetime: &'a Lifetime) -> V::Result {
342 let Lifetime { id: _, ident } = lifetime;
343 visitor.visit_ident(ident)
344}
345
346pub fn walk_poly_trait_ref<'a, V>(visitor: &mut V, trait_ref: &'a PolyTraitRef) -> V::Result
347where
348 V: Visitor<'a>,
349{
350 let PolyTraitRef { bound_generic_params, modifiers: _, trait_ref, span: _ } = trait_ref;
351 walk_list!(visitor, visit_generic_param, bound_generic_params);
352 visitor.visit_trait_ref(trait_ref)
353}
354
355pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitRef) -> V::Result {
356 let TraitRef { path, ref_id } = trait_ref;
357 visitor.visit_path(path, *ref_id)
358}
359
360impl WalkItemKind for ItemKind {
361 type Ctxt = ();
362 fn walk<'a, V: Visitor<'a>>(
363 &'a self,
364 span: Span,
365 id: NodeId,
366 ident: &'a Ident,
367 vis: &'a Visibility,
368 _ctxt: Self::Ctxt,
369 visitor: &mut V,
370 ) -> V::Result {
371 match self {
372 ItemKind::ExternCrate(_rename) => {}
373 ItemKind::Use(use_tree) => try_visit!(visitor.visit_use_tree(use_tree, id, false)),
374 ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
375 try_visit!(visitor.visit_ty(ty));
376 visit_opt!(visitor, visit_expr, expr);
377 }
378 ItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
379 try_visit!(visitor.visit_generics(generics));
380 try_visit!(visitor.visit_ty(ty));
381 visit_opt!(visitor, visit_expr, expr);
382 }
383 ItemKind::Fn(func) => {
384 let kind = FnKind::Fn(FnCtxt::Free, ident, vis, &*func);
385 try_visit!(visitor.visit_fn(kind, span, id));
386 }
387 ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
388 ModKind::Loaded(items, _inline, _inner_span, _) => {
389 walk_list!(visitor, visit_item, items);
390 }
391 ModKind::Unloaded => {}
392 },
393 ItemKind::ForeignMod(ForeignMod { extern_span: _, safety: _, abi: _, items }) => {
394 walk_list!(visitor, visit_foreign_item, items);
395 }
396 ItemKind::GlobalAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
397 ItemKind::TyAlias(box TyAlias {
398 generics,
399 bounds,
400 ty,
401 defaultness: _,
402 where_clauses: _,
403 }) => {
404 try_visit!(visitor.visit_generics(generics));
405 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
406 visit_opt!(visitor, visit_ty, ty);
407 }
408 ItemKind::Enum(enum_definition, generics) => {
409 try_visit!(visitor.visit_generics(generics));
410 try_visit!(visitor.visit_enum_def(enum_definition));
411 }
412 ItemKind::Impl(box Impl {
413 defaultness: _,
414 safety: _,
415 generics,
416 constness: _,
417 polarity: _,
418 of_trait,
419 self_ty,
420 items,
421 }) => {
422 try_visit!(visitor.visit_generics(generics));
423 visit_opt!(visitor, visit_trait_ref, of_trait);
424 try_visit!(visitor.visit_ty(self_ty));
425 walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
426 }
427 ItemKind::Struct(struct_definition, generics)
428 | ItemKind::Union(struct_definition, generics) => {
429 try_visit!(visitor.visit_generics(generics));
430 try_visit!(visitor.visit_variant_data(struct_definition));
431 }
432 ItemKind::Trait(box Trait { safety: _, is_auto: _, generics, bounds, items }) => {
433 try_visit!(visitor.visit_generics(generics));
434 walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
435 walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
436 }
437 ItemKind::TraitAlias(generics, bounds) => {
438 try_visit!(visitor.visit_generics(generics));
439 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
440 }
441 ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
442 ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, id)),
443 ItemKind::Delegation(box Delegation {
444 id,
445 qself,
446 path,
447 rename,
448 body,
449 from_glob: _,
450 }) => {
451 try_visit!(visitor.visit_qself(qself));
452 try_visit!(visitor.visit_path(path, *id));
453 visit_opt!(visitor, visit_ident, rename);
454 visit_opt!(visitor, visit_block, body);
455 }
456 ItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
457 try_visit!(visitor.visit_qself(qself));
458 try_visit!(visitor.visit_path(prefix, id));
459 if let Some(suffixes) = suffixes {
460 for (ident, rename) in suffixes {
461 visitor.visit_ident(ident);
462 if let Some(rename) = rename {
463 visitor.visit_ident(rename);
464 }
465 }
466 }
467 visit_opt!(visitor, visit_block, body);
468 }
469 }
470 V::Result::output()
471 }
472}
473
474pub fn walk_enum_def<'a, V: Visitor<'a>>(
475 visitor: &mut V,
476 EnumDef { variants }: &'a EnumDef,
477) -> V::Result {
478 walk_list!(visitor, visit_variant, variants);
479 V::Result::output()
480}
481
482pub fn walk_variant<'a, V: Visitor<'a>>(visitor: &mut V, variant: &'a Variant) -> V::Result
483where
484 V: Visitor<'a>,
485{
486 let Variant { attrs, id: _, span: _, vis, ident, data, disr_expr, is_placeholder: _ } = variant;
487 walk_list!(visitor, visit_attribute, attrs);
488 try_visit!(visitor.visit_vis(vis));
489 try_visit!(visitor.visit_ident(ident));
490 try_visit!(visitor.visit_variant_data(data));
491 visit_opt!(visitor, visit_variant_discr, disr_expr);
492 V::Result::output()
493}
494
495pub fn walk_expr_field<'a, V: Visitor<'a>>(visitor: &mut V, f: &'a ExprField) -> V::Result {
496 let ExprField { attrs, id: _, span: _, ident, expr, is_shorthand: _, is_placeholder: _ } = f;
497 walk_list!(visitor, visit_attribute, attrs);
498 try_visit!(visitor.visit_ident(ident));
499 try_visit!(visitor.visit_expr(expr));
500 V::Result::output()
501}
502
503pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) -> V::Result {
504 let PatField { ident, pat, is_shorthand: _, attrs, id: _, span: _, is_placeholder: _ } = fp;
505 walk_list!(visitor, visit_attribute, attrs);
506 try_visit!(visitor.visit_ident(ident));
507 try_visit!(visitor.visit_pat(pat));
508 V::Result::output()
509}
510
511pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) -> V::Result {
512 let Ty { id, kind, span: _, tokens: _ } = typ;
513 match kind {
514 TyKind::Slice(ty) | TyKind::Paren(ty) => try_visit!(visitor.visit_ty(ty)),
515 TyKind::Ptr(MutTy { ty, mutbl: _ }) => try_visit!(visitor.visit_ty(ty)),
516 TyKind::Ref(opt_lifetime, MutTy { ty, mutbl: _ })
517 | TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl: _ }) => {
518 visit_opt!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Ref);
519 try_visit!(visitor.visit_ty(ty));
520 }
521 TyKind::Tup(tuple_element_types) => {
522 walk_list!(visitor, visit_ty, tuple_element_types);
523 }
524 TyKind::BareFn(function_declaration) => {
525 let BareFnTy { safety: _, ext: _, generic_params, decl, decl_span: _ } =
526 &**function_declaration;
527 walk_list!(visitor, visit_generic_param, generic_params);
528 try_visit!(visitor.visit_fn_decl(decl));
529 }
530 TyKind::UnsafeBinder(binder) => {
531 walk_list!(visitor, visit_generic_param, &binder.generic_params);
532 try_visit!(visitor.visit_ty(&binder.inner_ty));
533 }
534 TyKind::Path(maybe_qself, path) => {
535 try_visit!(visitor.visit_qself(maybe_qself));
536 try_visit!(visitor.visit_path(path, *id));
537 }
538 TyKind::Pat(ty, pat) => {
539 try_visit!(visitor.visit_ty(ty));
540 try_visit!(visitor.visit_ty_pat(pat));
541 }
542 TyKind::Array(ty, length) => {
543 try_visit!(visitor.visit_ty(ty));
544 try_visit!(visitor.visit_anon_const(length));
545 }
546 TyKind::TraitObject(bounds, _syntax) => {
547 walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject);
548 }
549 TyKind::ImplTrait(_id, bounds) => {
550 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
551 }
552 TyKind::Typeof(expression) => try_visit!(visitor.visit_anon_const(expression)),
553 TyKind::Infer | TyKind::ImplicitSelf | TyKind::Dummy => {}
554 TyKind::Err(_guar) => {}
555 TyKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
556 TyKind::Never | TyKind::CVarArgs => {}
557 }
558 V::Result::output()
559}
560
561pub fn walk_ty_pat<'a, V: Visitor<'a>>(visitor: &mut V, tp: &'a TyPat) -> V::Result {
562 let TyPat { id: _, kind, span: _, tokens: _ } = tp;
563 match kind {
564 TyPatKind::Range(start, end, _include_end) => {
565 visit_opt!(visitor, visit_anon_const, start);
566 visit_opt!(visitor, visit_anon_const, end);
567 }
568 TyPatKind::Err(_) => {}
569 }
570 V::Result::output()
571}
572
573fn walk_qself<'a, V: Visitor<'a>>(visitor: &mut V, qself: &'a Option<P<QSelf>>) -> V::Result {
574 if let Some(qself) = qself {
575 let QSelf { ty, path_span: _, position: _ } = &**qself;
576 try_visit!(visitor.visit_ty(ty));
577 }
578 V::Result::output()
579}
580
581pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) -> V::Result {
582 let Path { span: _, segments, tokens: _ } = path;
583 walk_list!(visitor, visit_path_segment, segments);
584 V::Result::output()
585}
586
587pub fn walk_use_tree<'a, V: Visitor<'a>>(
588 visitor: &mut V,
589 use_tree: &'a UseTree,
590 id: NodeId,
591) -> V::Result {
592 let UseTree { prefix, kind, span: _ } = use_tree;
593 try_visit!(visitor.visit_path(prefix, id));
594 match kind {
595 UseTreeKind::Simple(rename) => {
596 visit_opt!(visitor, visit_ident, rename);
598 }
599 UseTreeKind::Glob => {}
600 UseTreeKind::Nested { items, span: _ } => {
601 for &(ref nested_tree, nested_id) in items {
602 try_visit!(visitor.visit_use_tree(nested_tree, nested_id, true));
603 }
604 }
605 }
606 V::Result::output()
607}
608
609pub fn walk_path_segment<'a, V: Visitor<'a>>(
610 visitor: &mut V,
611 segment: &'a PathSegment,
612) -> V::Result {
613 let PathSegment { ident, id: _, args } = segment;
614 try_visit!(visitor.visit_ident(ident));
615 visit_opt!(visitor, visit_generic_args, args);
616 V::Result::output()
617}
618
619pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs) -> V::Result
620where
621 V: Visitor<'a>,
622{
623 match generic_args {
624 GenericArgs::AngleBracketed(AngleBracketedArgs { span: _, args }) => {
625 for arg in args {
626 match arg {
627 AngleBracketedArg::Arg(a) => try_visit!(visitor.visit_generic_arg(a)),
628 AngleBracketedArg::Constraint(c) => {
629 try_visit!(visitor.visit_assoc_item_constraint(c))
630 }
631 }
632 }
633 }
634 GenericArgs::Parenthesized(data) => {
635 let ParenthesizedArgs { span: _, inputs, inputs_span: _, output } = data;
636 walk_list!(visitor, visit_ty, inputs);
637 try_visit!(visitor.visit_fn_ret_ty(output));
638 }
639 GenericArgs::ParenthesizedElided(_span) => {}
640 }
641 V::Result::output()
642}
643
644pub fn walk_generic_arg<'a, V>(visitor: &mut V, generic_arg: &'a GenericArg) -> V::Result
645where
646 V: Visitor<'a>,
647{
648 match generic_arg {
649 GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
650 GenericArg::Type(ty) => visitor.visit_ty(ty),
651 GenericArg::Const(ct) => visitor.visit_anon_const(ct),
652 }
653}
654
655pub fn walk_assoc_item_constraint<'a, V: Visitor<'a>>(
656 visitor: &mut V,
657 constraint: &'a AssocItemConstraint,
658) -> V::Result {
659 let AssocItemConstraint { id: _, ident, gen_args, kind, span: _ } = constraint;
660 try_visit!(visitor.visit_ident(ident));
661 visit_opt!(visitor, visit_generic_args, gen_args);
662 match kind {
663 AssocItemConstraintKind::Equality { term } => match term {
664 Term::Ty(ty) => try_visit!(visitor.visit_ty(ty)),
665 Term::Const(c) => try_visit!(visitor.visit_anon_const(c)),
666 },
667 AssocItemConstraintKind::Bound { bounds } => {
668 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
669 }
670 }
671 V::Result::output()
672}
673
674pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Result {
675 let Pat { id, kind, span: _, tokens: _ } = pattern;
676 match kind {
677 PatKind::TupleStruct(opt_qself, path, elems) => {
678 try_visit!(visitor.visit_qself(opt_qself));
679 try_visit!(visitor.visit_path(path, *id));
680 walk_list!(visitor, visit_pat, elems);
681 }
682 PatKind::Path(opt_qself, path) => {
683 try_visit!(visitor.visit_qself(opt_qself));
684 try_visit!(visitor.visit_path(path, *id))
685 }
686 PatKind::Struct(opt_qself, path, fields, _rest) => {
687 try_visit!(visitor.visit_qself(opt_qself));
688 try_visit!(visitor.visit_path(path, *id));
689 walk_list!(visitor, visit_pat_field, fields);
690 }
691 PatKind::Box(subpattern) | PatKind::Deref(subpattern) | PatKind::Paren(subpattern) => {
692 try_visit!(visitor.visit_pat(subpattern));
693 }
694 PatKind::Ref(subpattern, _ ) => {
695 try_visit!(visitor.visit_pat(subpattern));
696 }
697 PatKind::Ident(_bmode, ident, optional_subpattern) => {
698 try_visit!(visitor.visit_ident(ident));
699 visit_opt!(visitor, visit_pat, optional_subpattern);
700 }
701 PatKind::Expr(expression) => try_visit!(visitor.visit_expr(expression)),
702 PatKind::Range(lower_bound, upper_bound, _end) => {
703 visit_opt!(visitor, visit_expr, lower_bound);
704 visit_opt!(visitor, visit_expr, upper_bound);
705 }
706 PatKind::Guard(subpattern, guard_condition) => {
707 try_visit!(visitor.visit_pat(subpattern));
708 try_visit!(visitor.visit_expr(guard_condition));
709 }
710 PatKind::Wild | PatKind::Rest | PatKind::Never => {}
711 PatKind::Err(_guar) => {}
712 PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => {
713 walk_list!(visitor, visit_pat, elems);
714 }
715 PatKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
716 }
717 V::Result::output()
718}
719
720impl WalkItemKind for ForeignItemKind {
721 type Ctxt = ();
722 fn walk<'a, V: Visitor<'a>>(
723 &'a self,
724 span: Span,
725 id: NodeId,
726 ident: &'a Ident,
727 vis: &'a Visibility,
728 _ctxt: Self::Ctxt,
729 visitor: &mut V,
730 ) -> V::Result {
731 match self {
732 ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
733 try_visit!(visitor.visit_ty(ty));
734 visit_opt!(visitor, visit_expr, expr);
735 }
736 ForeignItemKind::Fn(func) => {
737 let kind = FnKind::Fn(FnCtxt::Foreign, ident, vis, &*func);
738 try_visit!(visitor.visit_fn(kind, span, id));
739 }
740 ForeignItemKind::TyAlias(box TyAlias {
741 generics,
742 bounds,
743 ty,
744 defaultness: _,
745 where_clauses: _,
746 }) => {
747 try_visit!(visitor.visit_generics(generics));
748 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
749 visit_opt!(visitor, visit_ty, ty);
750 }
751 ForeignItemKind::MacCall(mac) => {
752 try_visit!(visitor.visit_mac_call(mac));
753 }
754 }
755 V::Result::output()
756 }
757}
758
759pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) -> V::Result {
760 match bound {
761 GenericBound::Trait(trait_ref) => visitor.visit_poly_trait_ref(trait_ref),
762 GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound),
763 GenericBound::Use(args, _span) => {
764 walk_list!(visitor, visit_precise_capturing_arg, args);
765 V::Result::output()
766 }
767 }
768}
769
770pub fn walk_precise_capturing_arg<'a, V: Visitor<'a>>(
771 visitor: &mut V,
772 arg: &'a PreciseCapturingArg,
773) -> V::Result {
774 match arg {
775 PreciseCapturingArg::Lifetime(lt) => visitor.visit_lifetime(lt, LifetimeCtxt::GenericArg),
776 PreciseCapturingArg::Arg(path, id) => visitor.visit_path(path, *id),
777 }
778}
779
780pub fn walk_generic_param<'a, V: Visitor<'a>>(
781 visitor: &mut V,
782 param: &'a GenericParam,
783) -> V::Result {
784 let GenericParam { id: _, ident, attrs, bounds, is_placeholder: _, kind, colon_span: _ } =
785 param;
786 walk_list!(visitor, visit_attribute, attrs);
787 try_visit!(visitor.visit_ident(ident));
788 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
789 match kind {
790 GenericParamKind::Lifetime => (),
791 GenericParamKind::Type { default } => visit_opt!(visitor, visit_ty, default),
792 GenericParamKind::Const { ty, default, kw_span: _ } => {
793 try_visit!(visitor.visit_ty(ty));
794 visit_opt!(visitor, visit_anon_const, default);
795 }
796 }
797 V::Result::output()
798}
799
800pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) -> V::Result {
801 let Generics { params, where_clause, span: _ } = generics;
802 let WhereClause { has_where_token: _, predicates, span: _ } = where_clause;
803 walk_list!(visitor, visit_generic_param, params);
804 walk_list!(visitor, visit_where_predicate, predicates);
805 V::Result::output()
806}
807
808pub fn walk_closure_binder<'a, V: Visitor<'a>>(
809 visitor: &mut V,
810 binder: &'a ClosureBinder,
811) -> V::Result {
812 match binder {
813 ClosureBinder::NotPresent => {}
814 ClosureBinder::For { generic_params, span: _ } => {
815 walk_list!(visitor, visit_generic_param, generic_params)
816 }
817 }
818 V::Result::output()
819}
820
821pub fn walk_contract<'a, V: Visitor<'a>>(visitor: &mut V, c: &'a FnContract) -> V::Result {
822 let FnContract { requires, ensures } = c;
823 if let Some(pred) = requires {
824 visitor.visit_expr(pred);
825 }
826 if let Some(pred) = ensures {
827 visitor.visit_expr(pred);
828 }
829 V::Result::output()
830}
831
832pub fn walk_where_predicate<'a, V: Visitor<'a>>(
833 visitor: &mut V,
834 predicate: &'a WherePredicate,
835) -> V::Result {
836 let WherePredicate { attrs, kind, id: _, span: _, is_placeholder: _ } = predicate;
837 walk_list!(visitor, visit_attribute, attrs);
838 visitor.visit_where_predicate_kind(kind)
839}
840
841pub fn walk_where_predicate_kind<'a, V: Visitor<'a>>(
842 visitor: &mut V,
843 kind: &'a WherePredicateKind,
844) -> V::Result {
845 match kind {
846 WherePredicateKind::BoundPredicate(WhereBoundPredicate {
847 bounded_ty,
848 bounds,
849 bound_generic_params,
850 }) => {
851 walk_list!(visitor, visit_generic_param, bound_generic_params);
852 try_visit!(visitor.visit_ty(bounded_ty));
853 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
854 }
855 WherePredicateKind::RegionPredicate(WhereRegionPredicate { lifetime, bounds }) => {
856 try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound));
857 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
858 }
859 WherePredicateKind::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty }) => {
860 try_visit!(visitor.visit_ty(lhs_ty));
861 try_visit!(visitor.visit_ty(rhs_ty));
862 }
863 }
864 V::Result::output()
865}
866
867pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) -> V::Result {
868 match ret_ty {
869 FnRetTy::Default(_span) => {}
870 FnRetTy::Ty(output_ty) => try_visit!(visitor.visit_ty(output_ty)),
871 }
872 V::Result::output()
873}
874
875pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
876 let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
877 visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
878 V::Result::output()
879}
880
881pub fn walk_fn_decl<'a, V: Visitor<'a>>(
882 visitor: &mut V,
883 FnDecl { inputs, output }: &'a FnDecl,
884) -> V::Result {
885 walk_list!(visitor, visit_param, inputs);
886 visitor.visit_fn_ret_ty(output)
887}
888
889pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
890 match kind {
891 FnKind::Fn(
892 _ctxt,
893 _ident,
894 _vis,
895 Fn {
896 defaultness: _,
897 sig: FnSig { header, decl, span: _ },
898 generics,
899 contract,
900 body,
901 define_opaque,
902 },
903 ) => {
904 try_visit!(visitor.visit_fn_header(header));
906 try_visit!(visitor.visit_generics(generics));
907 try_visit!(visitor.visit_fn_decl(decl));
908 visit_opt!(visitor, visit_contract, contract);
909 visit_opt!(visitor, visit_block, body);
910 for (id, path) in define_opaque.iter().flatten() {
911 try_visit!(visitor.visit_path(path, *id))
912 }
913 }
914 FnKind::Closure(binder, coroutine_kind, decl, body) => {
915 try_visit!(visitor.visit_closure_binder(binder));
916 visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
917 try_visit!(visitor.visit_fn_decl(decl));
918 try_visit!(visitor.visit_expr(body));
919 }
920 }
921 V::Result::output()
922}
923
924impl WalkItemKind for AssocItemKind {
925 type Ctxt = AssocCtxt;
926 fn walk<'a, V: Visitor<'a>>(
927 &'a self,
928 span: Span,
929 id: NodeId,
930 ident: &'a Ident,
931 vis: &'a Visibility,
932 ctxt: Self::Ctxt,
933 visitor: &mut V,
934 ) -> V::Result {
935 match self {
936 AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
937 try_visit!(visitor.visit_generics(generics));
938 try_visit!(visitor.visit_ty(ty));
939 visit_opt!(visitor, visit_expr, expr);
940 }
941 AssocItemKind::Fn(func) => {
942 let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, vis, &*func);
943 try_visit!(visitor.visit_fn(kind, span, id));
944 }
945 AssocItemKind::Type(box TyAlias {
946 generics,
947 bounds,
948 ty,
949 defaultness: _,
950 where_clauses: _,
951 }) => {
952 try_visit!(visitor.visit_generics(generics));
953 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
954 visit_opt!(visitor, visit_ty, ty);
955 }
956 AssocItemKind::MacCall(mac) => {
957 try_visit!(visitor.visit_mac_call(mac));
958 }
959 AssocItemKind::Delegation(box Delegation {
960 id,
961 qself,
962 path,
963 rename,
964 body,
965 from_glob: _,
966 }) => {
967 try_visit!(visitor.visit_qself(qself));
968 try_visit!(visitor.visit_path(path, *id));
969 visit_opt!(visitor, visit_ident, rename);
970 visit_opt!(visitor, visit_block, body);
971 }
972 AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
973 try_visit!(visitor.visit_qself(qself));
974 try_visit!(visitor.visit_path(prefix, id));
975 if let Some(suffixes) = suffixes {
976 for (ident, rename) in suffixes {
977 visitor.visit_ident(ident);
978 if let Some(rename) = rename {
979 visitor.visit_ident(rename);
980 }
981 }
982 }
983 visit_opt!(visitor, visit_block, body);
984 }
985 }
986 V::Result::output()
987 }
988}
989
990pub fn walk_item<'a, V: Visitor<'a>>(
991 visitor: &mut V,
992 item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
993) -> V::Result {
994 walk_item_ctxt(visitor, item, ())
995}
996
997pub fn walk_assoc_item<'a, V: Visitor<'a>>(
998 visitor: &mut V,
999 item: &'a AssocItem,
1000 ctxt: AssocCtxt,
1001) -> V::Result {
1002 walk_item_ctxt(visitor, item, ctxt)
1003}
1004
1005fn walk_item_ctxt<'a, V: Visitor<'a>, K: WalkItemKind>(
1006 visitor: &mut V,
1007 item: &'a Item<K>,
1008 ctxt: K::Ctxt,
1009) -> V::Result {
1010 let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
1011 walk_list!(visitor, visit_attribute, attrs);
1012 try_visit!(visitor.visit_vis(vis));
1013 try_visit!(visitor.visit_ident(ident));
1014 try_visit!(kind.walk(*span, *id, ident, vis, ctxt, visitor));
1015 V::Result::output()
1016}
1017
1018pub fn walk_struct_def<'a, V: Visitor<'a>>(
1019 visitor: &mut V,
1020 struct_definition: &'a VariantData,
1021) -> V::Result {
1022 walk_list!(visitor, visit_field_def, struct_definition.fields());
1023 V::Result::output()
1024}
1025
1026pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) -> V::Result {
1027 let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _, safety: _, default } =
1028 field;
1029 walk_list!(visitor, visit_attribute, attrs);
1030 try_visit!(visitor.visit_vis(vis));
1031 visit_opt!(visitor, visit_ident, ident);
1032 try_visit!(visitor.visit_ty(ty));
1033 visit_opt!(visitor, visit_anon_const, &*default);
1034 V::Result::output()
1035}
1036
1037pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::Result {
1038 let Block { stmts, id: _, rules: _, span: _, tokens: _, could_be_bare_literal: _ } = block;
1039 walk_list!(visitor, visit_stmt, stmts);
1040 V::Result::output()
1041}
1042
1043pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
1044 let Stmt { id: _, kind, span: _ } = statement;
1045 match kind {
1046 StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
1047 StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
1048 StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
1049 StmtKind::Empty => {}
1050 StmtKind::MacCall(mac) => {
1051 let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
1052 walk_list!(visitor, visit_attribute, attrs);
1053 try_visit!(visitor.visit_mac_call(mac));
1054 }
1055 }
1056 V::Result::output()
1057}
1058
1059pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) -> V::Result {
1060 let MacCall { path, args: _ } = mac;
1061 visitor.visit_path(path, DUMMY_NODE_ID)
1062}
1063
1064pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) -> V::Result {
1065 let AnonConst { id: _, value } = constant;
1066 visitor.visit_expr(value)
1067}
1068
1069pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) -> V::Result {
1070 let InlineAsm {
1071 asm_macro: _,
1072 template: _,
1073 template_strs: _,
1074 operands,
1075 clobber_abis: _,
1076 options: _,
1077 line_spans: _,
1078 } = asm;
1079 for (op, _span) in operands {
1080 match op {
1081 InlineAsmOperand::In { expr, reg: _ }
1082 | InlineAsmOperand::Out { expr: Some(expr), reg: _, late: _ }
1083 | InlineAsmOperand::InOut { expr, reg: _, late: _ } => {
1084 try_visit!(visitor.visit_expr(expr))
1085 }
1086 InlineAsmOperand::Out { expr: None, reg: _, late: _ } => {}
1087 InlineAsmOperand::SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
1088 try_visit!(visitor.visit_expr(in_expr));
1089 visit_opt!(visitor, visit_expr, out_expr);
1090 }
1091 InlineAsmOperand::Const { anon_const } => {
1092 try_visit!(visitor.visit_anon_const(anon_const))
1093 }
1094 InlineAsmOperand::Sym { sym } => try_visit!(visitor.visit_inline_asm_sym(sym)),
1095 InlineAsmOperand::Label { block } => try_visit!(visitor.visit_block(block)),
1096 }
1097 }
1098 V::Result::output()
1099}
1100
1101pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(
1102 visitor: &mut V,
1103 InlineAsmSym { id, qself, path }: &'a InlineAsmSym,
1104) -> V::Result {
1105 try_visit!(visitor.visit_qself(qself));
1106 visitor.visit_path(path, *id)
1107}
1108
1109pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs) -> V::Result {
1110 let FormatArgs { span: _, template: _, arguments, uncooked_fmt_str: _ } = fmt;
1111 for FormatArgument { kind, expr } in arguments.all_args() {
1112 match kind {
1113 FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => {
1114 try_visit!(visitor.visit_ident(ident))
1115 }
1116 FormatArgumentKind::Normal => {}
1117 }
1118 try_visit!(visitor.visit_expr(expr));
1119 }
1120 V::Result::output()
1121}
1122
1123pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V::Result {
1124 let Expr { id, kind, span, attrs, tokens: _ } = expression;
1125 walk_list!(visitor, visit_attribute, attrs);
1126 match kind {
1127 ExprKind::Array(subexpressions) => {
1128 walk_list!(visitor, visit_expr, subexpressions);
1129 }
1130 ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)),
1131 ExprKind::Repeat(element, count) => {
1132 try_visit!(visitor.visit_expr(element));
1133 try_visit!(visitor.visit_anon_const(count));
1134 }
1135 ExprKind::Struct(se) => {
1136 let StructExpr { qself, path, fields, rest } = &**se;
1137 try_visit!(visitor.visit_qself(qself));
1138 try_visit!(visitor.visit_path(path, *id));
1139 walk_list!(visitor, visit_expr_field, fields);
1140 match rest {
1141 StructRest::Base(expr) => try_visit!(visitor.visit_expr(expr)),
1142 StructRest::Rest(_span) => {}
1143 StructRest::None => {}
1144 }
1145 }
1146 ExprKind::Tup(subexpressions) => {
1147 walk_list!(visitor, visit_expr, subexpressions);
1148 }
1149 ExprKind::Call(callee_expression, arguments) => {
1150 try_visit!(visitor.visit_expr(callee_expression));
1151 walk_list!(visitor, visit_expr, arguments);
1152 }
1153 ExprKind::MethodCall(box MethodCall { seg, receiver, args, span: _ }) => {
1154 try_visit!(visitor.visit_expr(receiver));
1155 try_visit!(visitor.visit_path_segment(seg));
1156 walk_list!(visitor, visit_expr, args);
1157 }
1158 ExprKind::Binary(_op, left_expression, right_expression) => {
1159 try_visit!(visitor.visit_expr(left_expression));
1160 try_visit!(visitor.visit_expr(right_expression));
1161 }
1162 ExprKind::AddrOf(_kind, _mutbl, subexpression) => {
1163 try_visit!(visitor.visit_expr(subexpression));
1164 }
1165 ExprKind::Unary(_op, subexpression) => {
1166 try_visit!(visitor.visit_expr(subexpression));
1167 }
1168 ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => {
1169 try_visit!(visitor.visit_expr(subexpression));
1170 try_visit!(visitor.visit_ty(typ));
1171 }
1172 ExprKind::Let(pat, expr, _span, _recovered) => {
1173 try_visit!(visitor.visit_pat(pat));
1174 try_visit!(visitor.visit_expr(expr));
1175 }
1176 ExprKind::If(head_expression, if_block, optional_else) => {
1177 try_visit!(visitor.visit_expr(head_expression));
1178 try_visit!(visitor.visit_block(if_block));
1179 visit_opt!(visitor, visit_expr, optional_else);
1180 }
1181 ExprKind::While(subexpression, block, opt_label) => {
1182 visit_opt!(visitor, visit_label, opt_label);
1183 try_visit!(visitor.visit_expr(subexpression));
1184 try_visit!(visitor.visit_block(block));
1185 }
1186 ExprKind::ForLoop { pat, iter, body, label, kind: _ } => {
1187 visit_opt!(visitor, visit_label, label);
1188 try_visit!(visitor.visit_pat(pat));
1189 try_visit!(visitor.visit_expr(iter));
1190 try_visit!(visitor.visit_block(body));
1191 }
1192 ExprKind::Loop(block, opt_label, _span) => {
1193 visit_opt!(visitor, visit_label, opt_label);
1194 try_visit!(visitor.visit_block(block));
1195 }
1196 ExprKind::Match(subexpression, arms, _kind) => {
1197 try_visit!(visitor.visit_expr(subexpression));
1198 walk_list!(visitor, visit_arm, arms);
1199 }
1200 ExprKind::Closure(box Closure {
1201 binder,
1202 capture_clause,
1203 coroutine_kind,
1204 constness: _,
1205 movability: _,
1206 fn_decl,
1207 body,
1208 fn_decl_span: _,
1209 fn_arg_span: _,
1210 }) => {
1211 try_visit!(visitor.visit_capture_by(capture_clause));
1212 try_visit!(visitor.visit_fn(
1213 FnKind::Closure(binder, coroutine_kind, fn_decl, body),
1214 *span,
1215 *id
1216 ));
1217 }
1218 ExprKind::Block(block, opt_label) => {
1219 visit_opt!(visitor, visit_label, opt_label);
1220 try_visit!(visitor.visit_block(block));
1221 }
1222 ExprKind::Gen(_capt, body, _kind, _decl_span) => try_visit!(visitor.visit_block(body)),
1223 ExprKind::Await(expr, _span) => try_visit!(visitor.visit_expr(expr)),
1224 ExprKind::Use(expr, _span) => try_visit!(visitor.visit_expr(expr)),
1225 ExprKind::Assign(lhs, rhs, _span) => {
1226 try_visit!(visitor.visit_expr(lhs));
1227 try_visit!(visitor.visit_expr(rhs));
1228 }
1229 ExprKind::AssignOp(_op, left_expression, right_expression) => {
1230 try_visit!(visitor.visit_expr(left_expression));
1231 try_visit!(visitor.visit_expr(right_expression));
1232 }
1233 ExprKind::Field(subexpression, ident) => {
1234 try_visit!(visitor.visit_expr(subexpression));
1235 try_visit!(visitor.visit_ident(ident));
1236 }
1237 ExprKind::Index(main_expression, index_expression, _span) => {
1238 try_visit!(visitor.visit_expr(main_expression));
1239 try_visit!(visitor.visit_expr(index_expression));
1240 }
1241 ExprKind::Range(start, end, _limit) => {
1242 visit_opt!(visitor, visit_expr, start);
1243 visit_opt!(visitor, visit_expr, end);
1244 }
1245 ExprKind::Underscore => {}
1246 ExprKind::Path(maybe_qself, path) => {
1247 try_visit!(visitor.visit_qself(maybe_qself));
1248 try_visit!(visitor.visit_path(path, *id));
1249 }
1250 ExprKind::Break(opt_label, opt_expr) => {
1251 visit_opt!(visitor, visit_label, opt_label);
1252 visit_opt!(visitor, visit_expr, opt_expr);
1253 }
1254 ExprKind::Continue(opt_label) => {
1255 visit_opt!(visitor, visit_label, opt_label);
1256 }
1257 ExprKind::Ret(optional_expression) => {
1258 visit_opt!(visitor, visit_expr, optional_expression);
1259 }
1260 ExprKind::Yeet(optional_expression) => {
1261 visit_opt!(visitor, visit_expr, optional_expression);
1262 }
1263 ExprKind::Become(expr) => try_visit!(visitor.visit_expr(expr)),
1264 ExprKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
1265 ExprKind::Paren(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
1266 ExprKind::InlineAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
1267 ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)),
1268 ExprKind::OffsetOf(container, fields) => {
1269 try_visit!(visitor.visit_ty(container));
1270 walk_list!(visitor, visit_ident, fields.iter());
1271 }
1272 ExprKind::Yield(kind) => {
1273 visit_opt!(visitor, visit_expr, kind.expr());
1274 }
1275 ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
1276 ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)),
1277 ExprKind::Lit(_token) => {}
1278 ExprKind::IncludedBytes(_bytes) => {}
1279 ExprKind::UnsafeBinderCast(_kind, expr, ty) => {
1280 try_visit!(visitor.visit_expr(expr));
1281 visit_opt!(visitor, visit_ty, ty);
1282 }
1283 ExprKind::Err(_guar) => {}
1284 ExprKind::Dummy => {}
1285 }
1286
1287 V::Result::output()
1288}
1289
1290pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::Result {
1291 let Param { attrs, ty, pat, id: _, span: _, is_placeholder: _ } = param;
1292 walk_list!(visitor, visit_attribute, attrs);
1293 try_visit!(visitor.visit_pat(pat));
1294 try_visit!(visitor.visit_ty(ty));
1295 V::Result::output()
1296}
1297
1298pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) -> V::Result {
1299 let Arm { attrs, pat, guard, body, span: _, id: _, is_placeholder: _ } = arm;
1300 walk_list!(visitor, visit_attribute, attrs);
1301 try_visit!(visitor.visit_pat(pat));
1302 visit_opt!(visitor, visit_expr, guard);
1303 visit_opt!(visitor, visit_expr, body);
1304 V::Result::output()
1305}
1306
1307pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) -> V::Result {
1308 let Visibility { kind, span: _, tokens: _ } = vis;
1309 match kind {
1310 VisibilityKind::Restricted { path, id, shorthand: _ } => {
1311 try_visit!(visitor.visit_path(path, *id));
1312 }
1313 VisibilityKind::Public | VisibilityKind::Inherited => {}
1314 }
1315 V::Result::output()
1316}
1317
1318pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) -> V::Result {
1319 let Attribute { kind, id: _, style: _, span: _ } = attr;
1320 match kind {
1321 AttrKind::Normal(normal) => {
1322 let NormalAttr { item, tokens: _ } = &**normal;
1323 let AttrItem { unsafety: _, path, args, tokens: _ } = item;
1324 try_visit!(visitor.visit_path(path, DUMMY_NODE_ID));
1325 try_visit!(walk_attr_args(visitor, args));
1326 }
1327 AttrKind::DocComment(_kind, _sym) => {}
1328 }
1329 V::Result::output()
1330}
1331
1332pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -> V::Result {
1333 match args {
1334 AttrArgs::Empty => {}
1335 AttrArgs::Delimited(_args) => {}
1336 AttrArgs::Eq { expr, .. } => try_visit!(visitor.visit_expr(expr)),
1337 }
1338 V::Result::output()
1339}