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 { ref 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 { kind, id: _, span: _ } = predicate;
837 visitor.visit_where_predicate_kind(kind)
838}
839
840pub fn walk_where_predicate_kind<'a, V: Visitor<'a>>(
841 visitor: &mut V,
842 kind: &'a WherePredicateKind,
843) -> V::Result {
844 match kind {
845 WherePredicateKind::BoundPredicate(WhereBoundPredicate {
846 bounded_ty,
847 bounds,
848 bound_generic_params,
849 }) => {
850 walk_list!(visitor, visit_generic_param, bound_generic_params);
851 try_visit!(visitor.visit_ty(bounded_ty));
852 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
853 }
854 WherePredicateKind::RegionPredicate(WhereRegionPredicate { lifetime, bounds }) => {
855 try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound));
856 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
857 }
858 WherePredicateKind::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty }) => {
859 try_visit!(visitor.visit_ty(lhs_ty));
860 try_visit!(visitor.visit_ty(rhs_ty));
861 }
862 }
863 V::Result::output()
864}
865
866pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) -> V::Result {
867 match ret_ty {
868 FnRetTy::Default(_span) => {}
869 FnRetTy::Ty(output_ty) => try_visit!(visitor.visit_ty(output_ty)),
870 }
871 V::Result::output()
872}
873
874pub fn walk_fn_header<'a, V: Visitor<'a>>(visitor: &mut V, fn_header: &'a FnHeader) -> V::Result {
875 let FnHeader { safety: _, coroutine_kind, constness: _, ext: _ } = fn_header;
876 visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
877 V::Result::output()
878}
879
880pub fn walk_fn_decl<'a, V: Visitor<'a>>(
881 visitor: &mut V,
882 FnDecl { inputs, output }: &'a FnDecl,
883) -> V::Result {
884 walk_list!(visitor, visit_param, inputs);
885 visitor.visit_fn_ret_ty(output)
886}
887
888pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
889 match kind {
890 FnKind::Fn(
891 _ctxt,
892 _ident,
893 _vis,
894 Fn { defaultness: _, sig: FnSig { header, decl, span: _ }, generics, contract, body },
895 ) => {
896 try_visit!(visitor.visit_fn_header(header));
898 try_visit!(visitor.visit_generics(generics));
899 try_visit!(visitor.visit_fn_decl(decl));
900 visit_opt!(visitor, visit_contract, contract);
901 visit_opt!(visitor, visit_block, body);
902 }
903 FnKind::Closure(binder, coroutine_kind, decl, body) => {
904 try_visit!(visitor.visit_closure_binder(binder));
905 visit_opt!(visitor, visit_coroutine_kind, coroutine_kind.as_ref());
906 try_visit!(visitor.visit_fn_decl(decl));
907 try_visit!(visitor.visit_expr(body));
908 }
909 }
910 V::Result::output()
911}
912
913impl WalkItemKind for AssocItemKind {
914 type Ctxt = AssocCtxt;
915 fn walk<'a, V: Visitor<'a>>(
916 &'a self,
917 span: Span,
918 id: NodeId,
919 ident: &'a Ident,
920 vis: &'a Visibility,
921 ctxt: Self::Ctxt,
922 visitor: &mut V,
923 ) -> V::Result {
924 match self {
925 AssocItemKind::Const(box ConstItem { defaultness: _, generics, ty, expr }) => {
926 try_visit!(visitor.visit_generics(generics));
927 try_visit!(visitor.visit_ty(ty));
928 visit_opt!(visitor, visit_expr, expr);
929 }
930 AssocItemKind::Fn(func) => {
931 let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, vis, &*func);
932 try_visit!(visitor.visit_fn(kind, span, id));
933 }
934 AssocItemKind::Type(box TyAlias {
935 generics,
936 bounds,
937 ty,
938 defaultness: _,
939 where_clauses: _,
940 }) => {
941 try_visit!(visitor.visit_generics(generics));
942 walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
943 visit_opt!(visitor, visit_ty, ty);
944 }
945 AssocItemKind::MacCall(mac) => {
946 try_visit!(visitor.visit_mac_call(mac));
947 }
948 AssocItemKind::Delegation(box Delegation {
949 id,
950 qself,
951 path,
952 rename,
953 body,
954 from_glob: _,
955 }) => {
956 try_visit!(visitor.visit_qself(qself));
957 try_visit!(visitor.visit_path(path, *id));
958 visit_opt!(visitor, visit_ident, rename);
959 visit_opt!(visitor, visit_block, body);
960 }
961 AssocItemKind::DelegationMac(box DelegationMac { qself, prefix, suffixes, body }) => {
962 try_visit!(visitor.visit_qself(qself));
963 try_visit!(visitor.visit_path(prefix, id));
964 if let Some(suffixes) = suffixes {
965 for (ident, rename) in suffixes {
966 visitor.visit_ident(ident);
967 if let Some(rename) = rename {
968 visitor.visit_ident(rename);
969 }
970 }
971 }
972 visit_opt!(visitor, visit_block, body);
973 }
974 }
975 V::Result::output()
976 }
977}
978
979pub fn walk_item<'a, V: Visitor<'a>>(
980 visitor: &mut V,
981 item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
982) -> V::Result {
983 walk_item_ctxt(visitor, item, ())
984}
985
986pub fn walk_assoc_item<'a, V: Visitor<'a>>(
987 visitor: &mut V,
988 item: &'a AssocItem,
989 ctxt: AssocCtxt,
990) -> V::Result {
991 walk_item_ctxt(visitor, item, ctxt)
992}
993
994fn walk_item_ctxt<'a, V: Visitor<'a>, K: WalkItemKind>(
995 visitor: &mut V,
996 item: &'a Item<K>,
997 ctxt: K::Ctxt,
998) -> V::Result {
999 let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
1000 walk_list!(visitor, visit_attribute, attrs);
1001 try_visit!(visitor.visit_vis(vis));
1002 try_visit!(visitor.visit_ident(ident));
1003 try_visit!(kind.walk(*span, *id, ident, vis, ctxt, visitor));
1004 V::Result::output()
1005}
1006
1007pub fn walk_struct_def<'a, V: Visitor<'a>>(
1008 visitor: &mut V,
1009 struct_definition: &'a VariantData,
1010) -> V::Result {
1011 walk_list!(visitor, visit_field_def, struct_definition.fields());
1012 V::Result::output()
1013}
1014
1015pub fn walk_field_def<'a, V: Visitor<'a>>(visitor: &mut V, field: &'a FieldDef) -> V::Result {
1016 let FieldDef { attrs, id: _, span: _, vis, ident, ty, is_placeholder: _, safety: _, default } =
1017 field;
1018 walk_list!(visitor, visit_attribute, attrs);
1019 try_visit!(visitor.visit_vis(vis));
1020 visit_opt!(visitor, visit_ident, ident);
1021 try_visit!(visitor.visit_ty(ty));
1022 visit_opt!(visitor, visit_anon_const, &*default);
1023 V::Result::output()
1024}
1025
1026pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) -> V::Result {
1027 let Block { stmts, id: _, rules: _, span: _, tokens: _, could_be_bare_literal: _ } = block;
1028 walk_list!(visitor, visit_stmt, stmts);
1029 V::Result::output()
1030}
1031
1032pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) -> V::Result {
1033 let Stmt { id: _, kind, span: _ } = statement;
1034 match kind {
1035 StmtKind::Let(local) => try_visit!(visitor.visit_local(local)),
1036 StmtKind::Item(item) => try_visit!(visitor.visit_item(item)),
1037 StmtKind::Expr(expr) | StmtKind::Semi(expr) => try_visit!(visitor.visit_expr(expr)),
1038 StmtKind::Empty => {}
1039 StmtKind::MacCall(mac) => {
1040 let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
1041 walk_list!(visitor, visit_attribute, attrs);
1042 try_visit!(visitor.visit_mac_call(mac));
1043 }
1044 }
1045 V::Result::output()
1046}
1047
1048pub fn walk_mac<'a, V: Visitor<'a>>(visitor: &mut V, mac: &'a MacCall) -> V::Result {
1049 let MacCall { path, args: _ } = mac;
1050 visitor.visit_path(path, DUMMY_NODE_ID)
1051}
1052
1053pub fn walk_anon_const<'a, V: Visitor<'a>>(visitor: &mut V, constant: &'a AnonConst) -> V::Result {
1054 let AnonConst { id: _, value } = constant;
1055 visitor.visit_expr(value)
1056}
1057
1058pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm) -> V::Result {
1059 let InlineAsm {
1060 asm_macro: _,
1061 template: _,
1062 template_strs: _,
1063 operands,
1064 clobber_abis: _,
1065 options: _,
1066 line_spans: _,
1067 } = asm;
1068 for (op, _span) in operands {
1069 match op {
1070 InlineAsmOperand::In { expr, reg: _ }
1071 | InlineAsmOperand::Out { expr: Some(expr), reg: _, late: _ }
1072 | InlineAsmOperand::InOut { expr, reg: _, late: _ } => {
1073 try_visit!(visitor.visit_expr(expr))
1074 }
1075 InlineAsmOperand::Out { expr: None, reg: _, late: _ } => {}
1076 InlineAsmOperand::SplitInOut { in_expr, out_expr, reg: _, late: _ } => {
1077 try_visit!(visitor.visit_expr(in_expr));
1078 visit_opt!(visitor, visit_expr, out_expr);
1079 }
1080 InlineAsmOperand::Const { anon_const } => {
1081 try_visit!(visitor.visit_anon_const(anon_const))
1082 }
1083 InlineAsmOperand::Sym { sym } => try_visit!(visitor.visit_inline_asm_sym(sym)),
1084 InlineAsmOperand::Label { block } => try_visit!(visitor.visit_block(block)),
1085 }
1086 }
1087 V::Result::output()
1088}
1089
1090pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(
1091 visitor: &mut V,
1092 InlineAsmSym { id, qself, path }: &'a InlineAsmSym,
1093) -> V::Result {
1094 try_visit!(visitor.visit_qself(qself));
1095 visitor.visit_path(path, *id)
1096}
1097
1098pub fn walk_format_args<'a, V: Visitor<'a>>(visitor: &mut V, fmt: &'a FormatArgs) -> V::Result {
1099 let FormatArgs { span: _, template: _, arguments, uncooked_fmt_str: _ } = fmt;
1100 for FormatArgument { kind, expr } in arguments.all_args() {
1101 match kind {
1102 FormatArgumentKind::Named(ident) | FormatArgumentKind::Captured(ident) => {
1103 try_visit!(visitor.visit_ident(ident))
1104 }
1105 FormatArgumentKind::Normal => {}
1106 }
1107 try_visit!(visitor.visit_expr(expr));
1108 }
1109 V::Result::output()
1110}
1111
1112pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V::Result {
1113 let Expr { id, kind, span, attrs, tokens: _ } = expression;
1114 walk_list!(visitor, visit_attribute, attrs);
1115 match kind {
1116 ExprKind::Array(subexpressions) => {
1117 walk_list!(visitor, visit_expr, subexpressions);
1118 }
1119 ExprKind::ConstBlock(anon_const) => try_visit!(visitor.visit_anon_const(anon_const)),
1120 ExprKind::Repeat(element, count) => {
1121 try_visit!(visitor.visit_expr(element));
1122 try_visit!(visitor.visit_anon_const(count));
1123 }
1124 ExprKind::Struct(se) => {
1125 let StructExpr { qself, path, fields, rest } = &**se;
1126 try_visit!(visitor.visit_qself(qself));
1127 try_visit!(visitor.visit_path(path, *id));
1128 walk_list!(visitor, visit_expr_field, fields);
1129 match rest {
1130 StructRest::Base(expr) => try_visit!(visitor.visit_expr(expr)),
1131 StructRest::Rest(_span) => {}
1132 StructRest::None => {}
1133 }
1134 }
1135 ExprKind::Tup(subexpressions) => {
1136 walk_list!(visitor, visit_expr, subexpressions);
1137 }
1138 ExprKind::Call(callee_expression, arguments) => {
1139 try_visit!(visitor.visit_expr(callee_expression));
1140 walk_list!(visitor, visit_expr, arguments);
1141 }
1142 ExprKind::MethodCall(box MethodCall { seg, receiver, args, span: _ }) => {
1143 try_visit!(visitor.visit_expr(receiver));
1144 try_visit!(visitor.visit_path_segment(seg));
1145 walk_list!(visitor, visit_expr, args);
1146 }
1147 ExprKind::Binary(_op, left_expression, right_expression) => {
1148 try_visit!(visitor.visit_expr(left_expression));
1149 try_visit!(visitor.visit_expr(right_expression));
1150 }
1151 ExprKind::AddrOf(_kind, _mutbl, subexpression) => {
1152 try_visit!(visitor.visit_expr(subexpression));
1153 }
1154 ExprKind::Unary(_op, subexpression) => {
1155 try_visit!(visitor.visit_expr(subexpression));
1156 }
1157 ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => {
1158 try_visit!(visitor.visit_expr(subexpression));
1159 try_visit!(visitor.visit_ty(typ));
1160 }
1161 ExprKind::Let(pat, expr, _span, _recovered) => {
1162 try_visit!(visitor.visit_pat(pat));
1163 try_visit!(visitor.visit_expr(expr));
1164 }
1165 ExprKind::If(head_expression, if_block, optional_else) => {
1166 try_visit!(visitor.visit_expr(head_expression));
1167 try_visit!(visitor.visit_block(if_block));
1168 visit_opt!(visitor, visit_expr, optional_else);
1169 }
1170 ExprKind::While(subexpression, block, opt_label) => {
1171 visit_opt!(visitor, visit_label, opt_label);
1172 try_visit!(visitor.visit_expr(subexpression));
1173 try_visit!(visitor.visit_block(block));
1174 }
1175 ExprKind::ForLoop { pat, iter, body, label, kind: _ } => {
1176 visit_opt!(visitor, visit_label, label);
1177 try_visit!(visitor.visit_pat(pat));
1178 try_visit!(visitor.visit_expr(iter));
1179 try_visit!(visitor.visit_block(body));
1180 }
1181 ExprKind::Loop(block, opt_label, _span) => {
1182 visit_opt!(visitor, visit_label, opt_label);
1183 try_visit!(visitor.visit_block(block));
1184 }
1185 ExprKind::Match(subexpression, arms, _kind) => {
1186 try_visit!(visitor.visit_expr(subexpression));
1187 walk_list!(visitor, visit_arm, arms);
1188 }
1189 ExprKind::Closure(box Closure {
1190 binder,
1191 capture_clause,
1192 coroutine_kind,
1193 constness: _,
1194 movability: _,
1195 fn_decl,
1196 body,
1197 fn_decl_span: _,
1198 fn_arg_span: _,
1199 }) => {
1200 try_visit!(visitor.visit_capture_by(capture_clause));
1201 try_visit!(visitor.visit_fn(
1202 FnKind::Closure(binder, coroutine_kind, fn_decl, body),
1203 *span,
1204 *id
1205 ))
1206 }
1207 ExprKind::Block(block, opt_label) => {
1208 visit_opt!(visitor, visit_label, opt_label);
1209 try_visit!(visitor.visit_block(block));
1210 }
1211 ExprKind::Gen(_capt, body, _kind, _decl_span) => try_visit!(visitor.visit_block(body)),
1212 ExprKind::Await(expr, _span) => try_visit!(visitor.visit_expr(expr)),
1213 ExprKind::Assign(lhs, rhs, _span) => {
1214 try_visit!(visitor.visit_expr(lhs));
1215 try_visit!(visitor.visit_expr(rhs));
1216 }
1217 ExprKind::AssignOp(_op, left_expression, right_expression) => {
1218 try_visit!(visitor.visit_expr(left_expression));
1219 try_visit!(visitor.visit_expr(right_expression));
1220 }
1221 ExprKind::Field(subexpression, ident) => {
1222 try_visit!(visitor.visit_expr(subexpression));
1223 try_visit!(visitor.visit_ident(ident));
1224 }
1225 ExprKind::Index(main_expression, index_expression, _span) => {
1226 try_visit!(visitor.visit_expr(main_expression));
1227 try_visit!(visitor.visit_expr(index_expression));
1228 }
1229 ExprKind::Range(start, end, _limit) => {
1230 visit_opt!(visitor, visit_expr, start);
1231 visit_opt!(visitor, visit_expr, end);
1232 }
1233 ExprKind::Underscore => {}
1234 ExprKind::Path(maybe_qself, path) => {
1235 try_visit!(visitor.visit_qself(maybe_qself));
1236 try_visit!(visitor.visit_path(path, *id));
1237 }
1238 ExprKind::Break(opt_label, opt_expr) => {
1239 visit_opt!(visitor, visit_label, opt_label);
1240 visit_opt!(visitor, visit_expr, opt_expr);
1241 }
1242 ExprKind::Continue(opt_label) => {
1243 visit_opt!(visitor, visit_label, opt_label);
1244 }
1245 ExprKind::Ret(optional_expression) => {
1246 visit_opt!(visitor, visit_expr, optional_expression);
1247 }
1248 ExprKind::Yeet(optional_expression) => {
1249 visit_opt!(visitor, visit_expr, optional_expression);
1250 }
1251 ExprKind::Become(expr) => try_visit!(visitor.visit_expr(expr)),
1252 ExprKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
1253 ExprKind::Paren(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
1254 ExprKind::InlineAsm(asm) => try_visit!(visitor.visit_inline_asm(asm)),
1255 ExprKind::FormatArgs(f) => try_visit!(visitor.visit_format_args(f)),
1256 ExprKind::OffsetOf(container, fields) => {
1257 try_visit!(visitor.visit_ty(container));
1258 walk_list!(visitor, visit_ident, fields.iter());
1259 }
1260 ExprKind::Yield(optional_expression) => {
1261 visit_opt!(visitor, visit_expr, optional_expression);
1262 }
1263 ExprKind::Try(subexpression) => try_visit!(visitor.visit_expr(subexpression)),
1264 ExprKind::TryBlock(body) => try_visit!(visitor.visit_block(body)),
1265 ExprKind::Lit(_token) => {}
1266 ExprKind::IncludedBytes(_bytes) => {}
1267 ExprKind::UnsafeBinderCast(_kind, expr, ty) => {
1268 try_visit!(visitor.visit_expr(expr));
1269 visit_opt!(visitor, visit_ty, ty);
1270 }
1271 ExprKind::Err(_guar) => {}
1272 ExprKind::Dummy => {}
1273 }
1274
1275 V::Result::output()
1276}
1277
1278pub fn walk_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Param) -> V::Result {
1279 let Param { attrs, ty, pat, id: _, span: _, is_placeholder: _ } = param;
1280 walk_list!(visitor, visit_attribute, attrs);
1281 try_visit!(visitor.visit_pat(pat));
1282 try_visit!(visitor.visit_ty(ty));
1283 V::Result::output()
1284}
1285
1286pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) -> V::Result {
1287 let Arm { attrs, pat, guard, body, span: _, id: _, is_placeholder: _ } = arm;
1288 walk_list!(visitor, visit_attribute, attrs);
1289 try_visit!(visitor.visit_pat(pat));
1290 visit_opt!(visitor, visit_expr, guard);
1291 visit_opt!(visitor, visit_expr, body);
1292 V::Result::output()
1293}
1294
1295pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) -> V::Result {
1296 let Visibility { kind, span: _, tokens: _ } = vis;
1297 match kind {
1298 VisibilityKind::Restricted { path, id, shorthand: _ } => {
1299 try_visit!(visitor.visit_path(path, *id));
1300 }
1301 VisibilityKind::Public | VisibilityKind::Inherited => {}
1302 }
1303 V::Result::output()
1304}
1305
1306pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) -> V::Result {
1307 let Attribute { kind, id: _, style: _, span: _ } = attr;
1308 match kind {
1309 AttrKind::Normal(normal) => {
1310 let NormalAttr { item, tokens: _ } = &**normal;
1311 let AttrItem { unsafety: _, path, args, tokens: _ } = item;
1312 try_visit!(visitor.visit_path(path, DUMMY_NODE_ID));
1313 try_visit!(walk_attr_args(visitor, args));
1314 }
1315 AttrKind::DocComment(_kind, _sym) => {}
1316 }
1317 V::Result::output()
1318}
1319
1320pub fn walk_attr_args<'a, V: Visitor<'a>>(visitor: &mut V, args: &'a AttrArgs) -> V::Result {
1321 match args {
1322 AttrArgs::Empty => {}
1323 AttrArgs::Delimited(_args) => {}
1324 AttrArgs::Eq { expr, .. } => try_visit!(visitor.visit_expr(expr)),
1325 }
1326 V::Result::output()
1327}