1use rustc_ast::Label;
68use rustc_ast::visit::{VisitorResult, try_visit, visit_opt, walk_list};
69use rustc_span::def_id::LocalDefId;
70use rustc_span::{Ident, Span, Symbol};
71
72use crate::hir::*;
73
74pub trait IntoVisitor<'hir> {
75 type Visitor: Visitor<'hir>;
76 fn into_visitor(&self) -> Self::Visitor;
77}
78
79#[derive(Copy, Clone, Debug)]
80pub enum FnKind<'a> {
81 ItemFn(Ident, &'a Generics<'a>, FnHeader),
83
84 Method(Ident, &'a FnSig<'a>),
86
87 Closure,
89}
90
91impl<'a> FnKind<'a> {
92 pub fn header(&self) -> Option<&FnHeader> {
93 match *self {
94 FnKind::ItemFn(_, _, ref header) => Some(header),
95 FnKind::Method(_, ref sig) => Some(&sig.header),
96 FnKind::Closure => None,
97 }
98 }
99
100 pub fn constness(self) -> Constness {
101 self.header().map_or(Constness::NotConst, |header| header.constness)
102 }
103
104 pub fn asyncness(self) -> IsAsync {
105 self.header().map_or(IsAsync::NotAsync, |header| header.asyncness)
106 }
107}
108
109pub trait HirTyCtxt<'hir> {
113 fn hir_node(&self, hir_id: HirId) -> Node<'hir>;
115 fn hir_body(&self, id: BodyId) -> &'hir Body<'hir>;
116 fn hir_item(&self, id: ItemId) -> &'hir Item<'hir>;
117 fn hir_trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir>;
118 fn hir_impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>;
119 fn hir_foreign_item(&self, id: ForeignItemId) -> &'hir ForeignItem<'hir>;
120}
121
122impl<'hir> HirTyCtxt<'hir> for ! {
124 fn hir_node(&self, _: HirId) -> Node<'hir> {
125 unreachable!();
126 }
127 fn hir_body(&self, _: BodyId) -> &'hir Body<'hir> {
128 unreachable!();
129 }
130 fn hir_item(&self, _: ItemId) -> &'hir Item<'hir> {
131 unreachable!();
132 }
133 fn hir_trait_item(&self, _: TraitItemId) -> &'hir TraitItem<'hir> {
134 unreachable!();
135 }
136 fn hir_impl_item(&self, _: ImplItemId) -> &'hir ImplItem<'hir> {
137 unreachable!();
138 }
139 fn hir_foreign_item(&self, _: ForeignItemId) -> &'hir ForeignItem<'hir> {
140 unreachable!();
141 }
142}
143
144pub mod nested_filter {
145 use super::HirTyCtxt;
146
147 pub trait NestedFilter<'hir> {
160 type MaybeTyCtxt: HirTyCtxt<'hir>;
161
162 const INTER: bool;
165 const INTRA: bool;
168 }
169
170 pub struct None(());
178 impl NestedFilter<'_> for None {
179 type MaybeTyCtxt = !;
180 const INTER: bool = false;
181 const INTRA: bool = false;
182 }
183}
184
185use nested_filter::NestedFilter;
186
187pub trait Visitor<'v>: Sized {
204 type MaybeTyCtxt: HirTyCtxt<'v> = <Self::NestedFilter as NestedFilter<'v>>::MaybeTyCtxt;
206
207 type NestedFilter: NestedFilter<'v> = nested_filter::None;
220
221 type Result: VisitorResult = ();
224
225 fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt {
228 panic!(
229 "maybe_tcx must be implemented or consider using \
230 `type NestedFilter = nested_filter::None` (the default)"
231 );
232 }
233
234 fn visit_nested_item(&mut self, id: ItemId) -> Self::Result {
243 if Self::NestedFilter::INTER {
244 let item = self.maybe_tcx().hir_item(id);
245 try_visit!(self.visit_item(item));
246 }
247 Self::Result::output()
248 }
249
250 fn visit_nested_trait_item(&mut self, id: TraitItemId) -> Self::Result {
254 if Self::NestedFilter::INTER {
255 let item = self.maybe_tcx().hir_trait_item(id);
256 try_visit!(self.visit_trait_item(item));
257 }
258 Self::Result::output()
259 }
260
261 fn visit_nested_impl_item(&mut self, id: ImplItemId) -> Self::Result {
265 if Self::NestedFilter::INTER {
266 let item = self.maybe_tcx().hir_impl_item(id);
267 try_visit!(self.visit_impl_item(item));
268 }
269 Self::Result::output()
270 }
271
272 fn visit_nested_foreign_item(&mut self, id: ForeignItemId) -> Self::Result {
276 if Self::NestedFilter::INTER {
277 let item = self.maybe_tcx().hir_foreign_item(id);
278 try_visit!(self.visit_foreign_item(item));
279 }
280 Self::Result::output()
281 }
282
283 fn visit_nested_body(&mut self, id: BodyId) -> Self::Result {
287 if Self::NestedFilter::INTRA {
288 let body = self.maybe_tcx().hir_body(id);
289 try_visit!(self.visit_body(body));
290 }
291 Self::Result::output()
292 }
293
294 fn visit_param(&mut self, param: &'v Param<'v>) -> Self::Result {
295 walk_param(self, param)
296 }
297
298 fn visit_item(&mut self, i: &'v Item<'v>) -> Self::Result {
301 walk_item(self, i)
302 }
303
304 fn visit_body(&mut self, b: &Body<'v>) -> Self::Result {
305 walk_body(self, b)
306 }
307
308 fn visit_id(&mut self, _hir_id: HirId) -> Self::Result {
311 Self::Result::output()
312 }
313 fn visit_name(&mut self, _name: Symbol) -> Self::Result {
314 Self::Result::output()
315 }
316 fn visit_ident(&mut self, ident: Ident) -> Self::Result {
317 walk_ident(self, ident)
318 }
319 fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, _n: HirId) -> Self::Result {
320 walk_mod(self, m)
321 }
322 fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) -> Self::Result {
323 walk_foreign_item(self, i)
324 }
325 fn visit_local(&mut self, l: &'v LetStmt<'v>) -> Self::Result {
326 walk_local(self, l)
327 }
328 fn visit_block(&mut self, b: &'v Block<'v>) -> Self::Result {
329 walk_block(self, b)
330 }
331 fn visit_stmt(&mut self, s: &'v Stmt<'v>) -> Self::Result {
332 walk_stmt(self, s)
333 }
334 fn visit_arm(&mut self, a: &'v Arm<'v>) -> Self::Result {
335 walk_arm(self, a)
336 }
337 fn visit_pat(&mut self, p: &'v Pat<'v>) -> Self::Result {
338 walk_pat(self, p)
339 }
340 fn visit_pat_field(&mut self, f: &'v PatField<'v>) -> Self::Result {
341 walk_pat_field(self, f)
342 }
343 fn visit_pat_expr(&mut self, expr: &'v PatExpr<'v>) -> Self::Result {
344 walk_pat_expr(self, expr)
345 }
346 fn visit_lit(&mut self, _hir_id: HirId, _lit: &'v Lit, _negated: bool) -> Self::Result {
347 Self::Result::output()
348 }
349 fn visit_anon_const(&mut self, c: &'v AnonConst) -> Self::Result {
350 walk_anon_const(self, c)
351 }
352 fn visit_inline_const(&mut self, c: &'v ConstBlock) -> Self::Result {
353 walk_inline_const(self, c)
354 }
355
356 fn visit_generic_arg(&mut self, generic_arg: &'v GenericArg<'v>) -> Self::Result {
357 walk_generic_arg(self, generic_arg)
358 }
359
360 fn visit_ty(&mut self, t: &'v Ty<'v, AmbigArg>) -> Self::Result {
368 walk_ty(self, t)
369 }
370
371 fn visit_const_arg(&mut self, c: &'v ConstArg<'v, AmbigArg>) -> Self::Result {
379 walk_ambig_const_arg(self, c)
380 }
381
382 #[allow(unused_variables)]
383 fn visit_infer(&mut self, inf_id: HirId, inf_span: Span, kind: InferKind<'v>) -> Self::Result {
384 self.visit_id(inf_id)
385 }
386
387 fn visit_lifetime(&mut self, lifetime: &'v Lifetime) -> Self::Result {
388 walk_lifetime(self, lifetime)
389 }
390
391 fn visit_expr(&mut self, ex: &'v Expr<'v>) -> Self::Result {
392 walk_expr(self, ex)
393 }
394 fn visit_expr_field(&mut self, field: &'v ExprField<'v>) -> Self::Result {
395 walk_expr_field(self, field)
396 }
397 fn visit_pattern_type_pattern(&mut self, p: &'v TyPat<'v>) -> Self::Result {
398 walk_ty_pat(self, p)
399 }
400 fn visit_generic_param(&mut self, p: &'v GenericParam<'v>) -> Self::Result {
401 walk_generic_param(self, p)
402 }
403 fn visit_const_param_default(&mut self, _param: HirId, ct: &'v ConstArg<'v>) -> Self::Result {
404 walk_const_param_default(self, ct)
405 }
406 fn visit_generics(&mut self, g: &'v Generics<'v>) -> Self::Result {
407 walk_generics(self, g)
408 }
409 fn visit_where_predicate(&mut self, predicate: &'v WherePredicate<'v>) -> Self::Result {
410 walk_where_predicate(self, predicate)
411 }
412 fn visit_fn_ret_ty(&mut self, ret_ty: &'v FnRetTy<'v>) -> Self::Result {
413 walk_fn_ret_ty(self, ret_ty)
414 }
415 fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) -> Self::Result {
416 walk_fn_decl(self, fd)
417 }
418 fn visit_fn(
419 &mut self,
420 fk: FnKind<'v>,
421 fd: &'v FnDecl<'v>,
422 b: BodyId,
423 _: Span,
424 id: LocalDefId,
425 ) -> Self::Result {
426 walk_fn(self, fk, fd, b, id)
427 }
428 fn visit_use(&mut self, path: &'v UsePath<'v>, hir_id: HirId) -> Self::Result {
429 walk_use(self, path, hir_id)
430 }
431 fn visit_trait_item(&mut self, ti: &'v TraitItem<'v>) -> Self::Result {
432 walk_trait_item(self, ti)
433 }
434 fn visit_trait_item_ref(&mut self, ii: &'v TraitItemRef) -> Self::Result {
435 walk_trait_item_ref(self, ii)
436 }
437 fn visit_impl_item(&mut self, ii: &'v ImplItem<'v>) -> Self::Result {
438 walk_impl_item(self, ii)
439 }
440 fn visit_foreign_item_ref(&mut self, ii: &'v ForeignItemRef) -> Self::Result {
441 walk_foreign_item_ref(self, ii)
442 }
443 fn visit_impl_item_ref(&mut self, ii: &'v ImplItemRef) -> Self::Result {
444 walk_impl_item_ref(self, ii)
445 }
446 fn visit_trait_ref(&mut self, t: &'v TraitRef<'v>) -> Self::Result {
447 walk_trait_ref(self, t)
448 }
449 fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) -> Self::Result {
450 walk_param_bound(self, bounds)
451 }
452 fn visit_precise_capturing_arg(&mut self, arg: &'v PreciseCapturingArg<'v>) -> Self::Result {
453 walk_precise_capturing_arg(self, arg)
454 }
455 fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>) -> Self::Result {
456 walk_poly_trait_ref(self, t)
457 }
458 fn visit_opaque_ty(&mut self, opaque: &'v OpaqueTy<'v>) -> Self::Result {
459 walk_opaque_ty(self, opaque)
460 }
461 fn visit_variant_data(&mut self, s: &'v VariantData<'v>) -> Self::Result {
462 walk_struct_def(self, s)
463 }
464 fn visit_field_def(&mut self, s: &'v FieldDef<'v>) -> Self::Result {
465 walk_field_def(self, s)
466 }
467 fn visit_enum_def(&mut self, enum_definition: &'v EnumDef<'v>) -> Self::Result {
468 walk_enum_def(self, enum_definition)
469 }
470 fn visit_variant(&mut self, v: &'v Variant<'v>) -> Self::Result {
471 walk_variant(self, v)
472 }
473 fn visit_label(&mut self, label: &'v Label) -> Self::Result {
474 walk_label(self, label)
475 }
476 fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, _span: Span) -> Self::Result {
478 walk_qpath(self, qpath, id)
479 }
480 fn visit_path(&mut self, path: &Path<'v>, _id: HirId) -> Self::Result {
481 walk_path(self, path)
482 }
483 fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) -> Self::Result {
484 walk_path_segment(self, path_segment)
485 }
486 fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) -> Self::Result {
487 walk_generic_args(self, generic_args)
488 }
489 fn visit_assoc_item_constraint(
490 &mut self,
491 constraint: &'v AssocItemConstraint<'v>,
492 ) -> Self::Result {
493 walk_assoc_item_constraint(self, constraint)
494 }
495 fn visit_attribute(&mut self, _attr: &'v Attribute) -> Self::Result {
496 Self::Result::output()
497 }
498 fn visit_associated_item_kind(&mut self, kind: &'v AssocItemKind) -> Self::Result {
499 walk_associated_item_kind(self, kind)
500 }
501 fn visit_defaultness(&mut self, defaultness: &'v Defaultness) -> Self::Result {
502 walk_defaultness(self, defaultness)
503 }
504 fn visit_inline_asm(&mut self, asm: &'v InlineAsm<'v>, id: HirId) -> Self::Result {
505 walk_inline_asm(self, asm, id)
506 }
507}
508
509pub trait VisitorExt<'v>: Visitor<'v> {
510 fn visit_ty_unambig(&mut self, t: &'v Ty<'v>) -> Self::Result {
516 walk_unambig_ty(self, t)
517 }
518 fn visit_const_arg_unambig(&mut self, c: &'v ConstArg<'v>) -> Self::Result {
524 walk_const_arg(self, c)
525 }
526}
527impl<'v, V: Visitor<'v>> VisitorExt<'v> for V {}
528
529pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) -> V::Result {
530 try_visit!(visitor.visit_id(param.hir_id));
531 visitor.visit_pat(param.pat)
532}
533
534pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::Result {
535 try_visit!(visitor.visit_id(item.hir_id()));
536 match item.kind {
537 ItemKind::ExternCrate(orig_name, ident) => {
538 visit_opt!(visitor, visit_name, orig_name);
539 try_visit!(visitor.visit_ident(ident));
540 }
541 ItemKind::Use(ref path, kind) => {
542 try_visit!(visitor.visit_use(path, item.hir_id()));
543 match kind {
544 UseKind::Single(ident) => try_visit!(visitor.visit_ident(ident)),
545 UseKind::Glob | UseKind::ListStem => {}
546 }
547 }
548 ItemKind::Static(ident, ref typ, _, body) => {
549 try_visit!(visitor.visit_ident(ident));
550 try_visit!(visitor.visit_ty_unambig(typ));
551 try_visit!(visitor.visit_nested_body(body));
552 }
553 ItemKind::Const(ident, ref typ, ref generics, body) => {
554 try_visit!(visitor.visit_ident(ident));
555 try_visit!(visitor.visit_ty_unambig(typ));
556 try_visit!(visitor.visit_generics(generics));
557 try_visit!(visitor.visit_nested_body(body));
558 }
559 ItemKind::Fn { ident, sig, generics, body: body_id, .. } => {
560 try_visit!(visitor.visit_ident(ident));
561 try_visit!(visitor.visit_fn(
562 FnKind::ItemFn(ident, generics, sig.header),
563 sig.decl,
564 body_id,
565 item.span,
566 item.owner_id.def_id,
567 ));
568 }
569 ItemKind::Macro(ident, _def, _kind) => {
570 try_visit!(visitor.visit_ident(ident));
571 }
572 ItemKind::Mod(ident, ref module) => {
573 try_visit!(visitor.visit_ident(ident));
574 try_visit!(visitor.visit_mod(module, item.span, item.hir_id()));
575 }
576 ItemKind::ForeignMod { abi: _, items } => {
577 walk_list!(visitor, visit_foreign_item_ref, items);
578 }
579 ItemKind::GlobalAsm { asm: _, fake_body } => {
580 try_visit!(visitor.visit_nested_body(fake_body));
585 }
586 ItemKind::TyAlias(ident, ref ty, ref generics) => {
587 try_visit!(visitor.visit_ident(ident));
588 try_visit!(visitor.visit_ty_unambig(ty));
589 try_visit!(visitor.visit_generics(generics));
590 }
591 ItemKind::Enum(ident, ref enum_definition, ref generics) => {
592 try_visit!(visitor.visit_ident(ident));
593 try_visit!(visitor.visit_generics(generics));
594 try_visit!(visitor.visit_enum_def(enum_definition));
595 }
596 ItemKind::Impl(Impl {
597 constness: _,
598 safety: _,
599 defaultness: _,
600 polarity: _,
601 defaultness_span: _,
602 generics,
603 of_trait,
604 self_ty,
605 items,
606 }) => {
607 try_visit!(visitor.visit_generics(generics));
608 visit_opt!(visitor, visit_trait_ref, of_trait);
609 try_visit!(visitor.visit_ty_unambig(self_ty));
610 walk_list!(visitor, visit_impl_item_ref, *items);
611 }
612 ItemKind::Struct(ident, ref struct_definition, ref generics)
613 | ItemKind::Union(ident, ref struct_definition, ref generics) => {
614 try_visit!(visitor.visit_ident(ident));
615 try_visit!(visitor.visit_generics(generics));
616 try_visit!(visitor.visit_variant_data(struct_definition));
617 }
618 ItemKind::Trait(_is_auto, _safety, ident, ref generics, bounds, trait_item_refs) => {
619 try_visit!(visitor.visit_ident(ident));
620 try_visit!(visitor.visit_generics(generics));
621 walk_list!(visitor, visit_param_bound, bounds);
622 walk_list!(visitor, visit_trait_item_ref, trait_item_refs);
623 }
624 ItemKind::TraitAlias(ident, ref generics, bounds) => {
625 try_visit!(visitor.visit_ident(ident));
626 try_visit!(visitor.visit_generics(generics));
627 walk_list!(visitor, visit_param_bound, bounds);
628 }
629 }
630 V::Result::output()
631}
632
633pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &Body<'v>) -> V::Result {
634 walk_list!(visitor, visit_param, body.params);
635 visitor.visit_expr(body.value)
636}
637
638pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) -> V::Result {
639 visitor.visit_name(ident.name)
640}
641
642pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>) -> V::Result {
643 walk_list!(visitor, visit_nested_item, module.item_ids.iter().copied());
644 V::Result::output()
645}
646
647pub fn walk_foreign_item<'v, V: Visitor<'v>>(
648 visitor: &mut V,
649 foreign_item: &'v ForeignItem<'v>,
650) -> V::Result {
651 try_visit!(visitor.visit_id(foreign_item.hir_id()));
652 try_visit!(visitor.visit_ident(foreign_item.ident));
653
654 match foreign_item.kind {
655 ForeignItemKind::Fn(ref sig, param_names, ref generics) => {
656 try_visit!(visitor.visit_generics(generics));
657 try_visit!(visitor.visit_fn_decl(sig.decl));
658 for ident in param_names.iter().copied() {
659 visit_opt!(visitor, visit_ident, ident);
660 }
661 }
662 ForeignItemKind::Static(ref typ, _, _) => {
663 try_visit!(visitor.visit_ty_unambig(typ));
664 }
665 ForeignItemKind::Type => (),
666 }
667 V::Result::output()
668}
669
670pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v LetStmt<'v>) -> V::Result {
671 visit_opt!(visitor, visit_expr, local.init);
674 try_visit!(visitor.visit_id(local.hir_id));
675 try_visit!(visitor.visit_pat(local.pat));
676 visit_opt!(visitor, visit_block, local.els);
677 visit_opt!(visitor, visit_ty_unambig, local.ty);
678 V::Result::output()
679}
680
681pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) -> V::Result {
682 try_visit!(visitor.visit_id(block.hir_id));
683 walk_list!(visitor, visit_stmt, block.stmts);
684 visit_opt!(visitor, visit_expr, block.expr);
685 V::Result::output()
686}
687
688pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) -> V::Result {
689 try_visit!(visitor.visit_id(statement.hir_id));
690 match statement.kind {
691 StmtKind::Let(ref local) => visitor.visit_local(local),
692 StmtKind::Item(item) => visitor.visit_nested_item(item),
693 StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
694 visitor.visit_expr(expression)
695 }
696 }
697}
698
699pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) -> V::Result {
700 try_visit!(visitor.visit_id(arm.hir_id));
701 try_visit!(visitor.visit_pat(arm.pat));
702 visit_opt!(visitor, visit_expr, arm.guard);
703 visitor.visit_expr(arm.body)
704}
705
706pub fn walk_ty_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v TyPat<'v>) -> V::Result {
707 try_visit!(visitor.visit_id(pattern.hir_id));
708 match pattern.kind {
709 TyPatKind::Range(lower_bound, upper_bound) => {
710 try_visit!(visitor.visit_const_arg_unambig(lower_bound));
711 try_visit!(visitor.visit_const_arg_unambig(upper_bound));
712 }
713 TyPatKind::Err(_) => (),
714 }
715 V::Result::output()
716}
717
718pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) -> V::Result {
719 try_visit!(visitor.visit_id(pattern.hir_id));
720 match pattern.kind {
721 PatKind::TupleStruct(ref qpath, children, _) => {
722 try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
723 walk_list!(visitor, visit_pat, children);
724 }
725 PatKind::Struct(ref qpath, fields, _) => {
726 try_visit!(visitor.visit_qpath(qpath, pattern.hir_id, pattern.span));
727 walk_list!(visitor, visit_pat_field, fields);
728 }
729 PatKind::Or(pats) => walk_list!(visitor, visit_pat, pats),
730 PatKind::Tuple(tuple_elements, _) => {
731 walk_list!(visitor, visit_pat, tuple_elements);
732 }
733 PatKind::Box(ref subpattern)
734 | PatKind::Deref(ref subpattern)
735 | PatKind::Ref(ref subpattern, _) => {
736 try_visit!(visitor.visit_pat(subpattern));
737 }
738 PatKind::Binding(_, _hir_id, ident, ref optional_subpattern) => {
739 try_visit!(visitor.visit_ident(ident));
740 visit_opt!(visitor, visit_pat, optional_subpattern);
741 }
742 PatKind::Expr(ref expression) => try_visit!(visitor.visit_pat_expr(expression)),
743 PatKind::Range(ref lower_bound, ref upper_bound, _) => {
744 visit_opt!(visitor, visit_pat_expr, lower_bound);
745 visit_opt!(visitor, visit_pat_expr, upper_bound);
746 }
747 PatKind::Never | PatKind::Wild | PatKind::Err(_) => (),
748 PatKind::Slice(prepatterns, ref slice_pattern, postpatterns) => {
749 walk_list!(visitor, visit_pat, prepatterns);
750 visit_opt!(visitor, visit_pat, slice_pattern);
751 walk_list!(visitor, visit_pat, postpatterns);
752 }
753 PatKind::Guard(subpat, condition) => {
754 try_visit!(visitor.visit_pat(subpat));
755 try_visit!(visitor.visit_expr(condition));
756 }
757 }
758 V::Result::output()
759}
760
761pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'v>) -> V::Result {
762 try_visit!(visitor.visit_id(field.hir_id));
763 try_visit!(visitor.visit_ident(field.ident));
764 visitor.visit_pat(field.pat)
765}
766
767pub fn walk_pat_expr<'v, V: Visitor<'v>>(visitor: &mut V, expr: &'v PatExpr<'v>) -> V::Result {
768 try_visit!(visitor.visit_id(expr.hir_id));
769 match &expr.kind {
770 PatExprKind::Lit { lit, negated } => visitor.visit_lit(expr.hir_id, lit, *negated),
771 PatExprKind::ConstBlock(c) => visitor.visit_inline_const(c),
772 PatExprKind::Path(qpath) => visitor.visit_qpath(qpath, expr.hir_id, expr.span),
773 }
774}
775
776pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) -> V::Result {
777 try_visit!(visitor.visit_id(constant.hir_id));
778 visitor.visit_nested_body(constant.body)
779}
780
781pub fn walk_inline_const<'v, V: Visitor<'v>>(
782 visitor: &mut V,
783 constant: &'v ConstBlock,
784) -> V::Result {
785 try_visit!(visitor.visit_id(constant.hir_id));
786 visitor.visit_nested_body(constant.body)
787}
788
789pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) -> V::Result {
790 try_visit!(visitor.visit_id(expression.hir_id));
791 match expression.kind {
792 ExprKind::Array(subexpressions) => {
793 walk_list!(visitor, visit_expr, subexpressions);
794 }
795 ExprKind::ConstBlock(ref const_block) => {
796 try_visit!(visitor.visit_inline_const(const_block))
797 }
798 ExprKind::Repeat(ref element, ref count) => {
799 try_visit!(visitor.visit_expr(element));
800 try_visit!(visitor.visit_const_arg_unambig(count));
801 }
802 ExprKind::Struct(ref qpath, fields, ref optional_base) => {
803 try_visit!(visitor.visit_qpath(qpath, expression.hir_id, expression.span));
804 walk_list!(visitor, visit_expr_field, fields);
805 match optional_base {
806 StructTailExpr::Base(base) => try_visit!(visitor.visit_expr(base)),
807 StructTailExpr::None | StructTailExpr::DefaultFields(_) => {}
808 }
809 }
810 ExprKind::Tup(subexpressions) => {
811 walk_list!(visitor, visit_expr, subexpressions);
812 }
813 ExprKind::Call(ref callee_expression, arguments) => {
814 try_visit!(visitor.visit_expr(callee_expression));
815 walk_list!(visitor, visit_expr, arguments);
816 }
817 ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
818 try_visit!(visitor.visit_path_segment(segment));
819 try_visit!(visitor.visit_expr(receiver));
820 walk_list!(visitor, visit_expr, arguments);
821 }
822 ExprKind::Use(expr, _) => {
823 try_visit!(visitor.visit_expr(expr));
824 }
825 ExprKind::Binary(_, ref left_expression, ref right_expression) => {
826 try_visit!(visitor.visit_expr(left_expression));
827 try_visit!(visitor.visit_expr(right_expression));
828 }
829 ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
830 try_visit!(visitor.visit_expr(subexpression));
831 }
832 ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
833 try_visit!(visitor.visit_expr(subexpression));
834 try_visit!(visitor.visit_ty_unambig(typ));
835 }
836 ExprKind::DropTemps(ref subexpression) => {
837 try_visit!(visitor.visit_expr(subexpression));
838 }
839 ExprKind::Let(LetExpr { span: _, pat, ty, init, recovered: _ }) => {
840 try_visit!(visitor.visit_expr(init));
842 try_visit!(visitor.visit_pat(pat));
843 visit_opt!(visitor, visit_ty_unambig, ty);
844 }
845 ExprKind::If(ref cond, ref then, ref else_opt) => {
846 try_visit!(visitor.visit_expr(cond));
847 try_visit!(visitor.visit_expr(then));
848 visit_opt!(visitor, visit_expr, else_opt);
849 }
850 ExprKind::Loop(ref block, ref opt_label, _, _) => {
851 visit_opt!(visitor, visit_label, opt_label);
852 try_visit!(visitor.visit_block(block));
853 }
854 ExprKind::Match(ref subexpression, arms, _) => {
855 try_visit!(visitor.visit_expr(subexpression));
856 walk_list!(visitor, visit_arm, arms);
857 }
858 ExprKind::Closure(&Closure {
859 def_id,
860 binder: _,
861 bound_generic_params,
862 fn_decl,
863 body,
864 capture_clause: _,
865 fn_decl_span: _,
866 fn_arg_span: _,
867 kind: _,
868 constness: _,
869 }) => {
870 walk_list!(visitor, visit_generic_param, bound_generic_params);
871 try_visit!(visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, def_id));
872 }
873 ExprKind::Block(ref block, ref opt_label) => {
874 visit_opt!(visitor, visit_label, opt_label);
875 try_visit!(visitor.visit_block(block));
876 }
877 ExprKind::Assign(ref lhs, ref rhs, _) => {
878 try_visit!(visitor.visit_expr(rhs));
879 try_visit!(visitor.visit_expr(lhs));
880 }
881 ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
882 try_visit!(visitor.visit_expr(right_expression));
883 try_visit!(visitor.visit_expr(left_expression));
884 }
885 ExprKind::Field(ref subexpression, ident) => {
886 try_visit!(visitor.visit_expr(subexpression));
887 try_visit!(visitor.visit_ident(ident));
888 }
889 ExprKind::Index(ref main_expression, ref index_expression, _) => {
890 try_visit!(visitor.visit_expr(main_expression));
891 try_visit!(visitor.visit_expr(index_expression));
892 }
893 ExprKind::Path(ref qpath) => {
894 try_visit!(visitor.visit_qpath(qpath, expression.hir_id, expression.span));
895 }
896 ExprKind::Break(ref destination, ref opt_expr) => {
897 visit_opt!(visitor, visit_label, &destination.label);
898 visit_opt!(visitor, visit_expr, opt_expr);
899 }
900 ExprKind::Continue(ref destination) => {
901 visit_opt!(visitor, visit_label, &destination.label);
902 }
903 ExprKind::Ret(ref optional_expression) => {
904 visit_opt!(visitor, visit_expr, optional_expression);
905 }
906 ExprKind::Become(ref expr) => try_visit!(visitor.visit_expr(expr)),
907 ExprKind::InlineAsm(ref asm) => {
908 try_visit!(visitor.visit_inline_asm(asm, expression.hir_id));
909 }
910 ExprKind::OffsetOf(ref container, ref fields) => {
911 try_visit!(visitor.visit_ty_unambig(container));
912 walk_list!(visitor, visit_ident, fields.iter().copied());
913 }
914 ExprKind::Yield(ref subexpression, _) => {
915 try_visit!(visitor.visit_expr(subexpression));
916 }
917 ExprKind::UnsafeBinderCast(_kind, expr, ty) => {
918 try_visit!(visitor.visit_expr(expr));
919 visit_opt!(visitor, visit_ty_unambig, ty);
920 }
921 ExprKind::Lit(lit) => try_visit!(visitor.visit_lit(expression.hir_id, lit, false)),
922 ExprKind::Err(_) => {}
923 }
924 V::Result::output()
925}
926
927pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) -> V::Result {
928 try_visit!(visitor.visit_id(field.hir_id));
929 try_visit!(visitor.visit_ident(field.ident));
930 visitor.visit_expr(field.expr)
931}
932pub enum InferKind<'hir> {
935 Ty(&'hir Ty<'hir>),
936 Const(&'hir ConstArg<'hir>),
937 Ambig(&'hir InferArg),
938}
939
940pub fn walk_generic_arg<'v, V: Visitor<'v>>(
941 visitor: &mut V,
942 generic_arg: &'v GenericArg<'v>,
943) -> V::Result {
944 match generic_arg {
945 GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
946 GenericArg::Type(ty) => visitor.visit_ty(ty),
947 GenericArg::Const(ct) => visitor.visit_const_arg(ct),
948 GenericArg::Infer(inf) => visitor.visit_infer(inf.hir_id, inf.span, InferKind::Ambig(inf)),
949 }
950}
951
952pub fn walk_unambig_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Result {
953 match typ.try_as_ambig_ty() {
954 Some(ambig_ty) => visitor.visit_ty(ambig_ty),
955 None => {
956 try_visit!(visitor.visit_id(typ.hir_id));
957 visitor.visit_infer(typ.hir_id, typ.span, InferKind::Ty(typ))
958 }
959 }
960}
961
962pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -> V::Result {
963 try_visit!(visitor.visit_id(typ.hir_id));
964
965 match typ.kind {
966 TyKind::Slice(ref ty) => try_visit!(visitor.visit_ty_unambig(ty)),
967 TyKind::Ptr(ref mutable_type) => try_visit!(visitor.visit_ty_unambig(mutable_type.ty)),
968 TyKind::Ref(ref lifetime, ref mutable_type) => {
969 try_visit!(visitor.visit_lifetime(lifetime));
970 try_visit!(visitor.visit_ty_unambig(mutable_type.ty));
971 }
972 TyKind::Never => {}
973 TyKind::Tup(tuple_element_types) => {
974 walk_list!(visitor, visit_ty_unambig, tuple_element_types);
975 }
976 TyKind::BareFn(ref function_declaration) => {
977 walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
978 try_visit!(visitor.visit_fn_decl(function_declaration.decl));
979 }
980 TyKind::UnsafeBinder(ref unsafe_binder) => {
981 walk_list!(visitor, visit_generic_param, unsafe_binder.generic_params);
982 try_visit!(visitor.visit_ty_unambig(unsafe_binder.inner_ty));
983 }
984 TyKind::Path(ref qpath) => {
985 try_visit!(visitor.visit_qpath(qpath, typ.hir_id, typ.span));
986 }
987 TyKind::OpaqueDef(opaque) => {
988 try_visit!(visitor.visit_opaque_ty(opaque));
989 }
990 TyKind::TraitAscription(bounds) => {
991 walk_list!(visitor, visit_param_bound, bounds);
992 }
993 TyKind::Array(ref ty, ref length) => {
994 try_visit!(visitor.visit_ty_unambig(ty));
995 try_visit!(visitor.visit_const_arg_unambig(length));
996 }
997 TyKind::TraitObject(bounds, ref lifetime) => {
998 for bound in bounds {
999 try_visit!(visitor.visit_poly_trait_ref(bound));
1000 }
1001 try_visit!(visitor.visit_lifetime(lifetime));
1002 }
1003 TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)),
1004 TyKind::InferDelegation(..) | TyKind::Err(_) => {}
1005 TyKind::Pat(ty, pat) => {
1006 try_visit!(visitor.visit_ty_unambig(ty));
1007 try_visit!(visitor.visit_pattern_type_pattern(pat));
1008 }
1009 }
1010 V::Result::output()
1011}
1012
1013pub fn walk_const_arg<'v, V: Visitor<'v>>(
1014 visitor: &mut V,
1015 const_arg: &'v ConstArg<'v>,
1016) -> V::Result {
1017 match const_arg.try_as_ambig_ct() {
1018 Some(ambig_ct) => visitor.visit_const_arg(ambig_ct),
1019 None => {
1020 try_visit!(visitor.visit_id(const_arg.hir_id));
1021 visitor.visit_infer(const_arg.hir_id, const_arg.span(), InferKind::Const(const_arg))
1022 }
1023 }
1024}
1025
1026pub fn walk_ambig_const_arg<'v, V: Visitor<'v>>(
1027 visitor: &mut V,
1028 const_arg: &'v ConstArg<'v, AmbigArg>,
1029) -> V::Result {
1030 try_visit!(visitor.visit_id(const_arg.hir_id));
1031 match &const_arg.kind {
1032 ConstArgKind::Path(qpath) => visitor.visit_qpath(qpath, const_arg.hir_id, qpath.span()),
1033 ConstArgKind::Anon(anon) => visitor.visit_anon_const(*anon),
1034 }
1035}
1036
1037pub fn walk_generic_param<'v, V: Visitor<'v>>(
1038 visitor: &mut V,
1039 param: &'v GenericParam<'v>,
1040) -> V::Result {
1041 try_visit!(visitor.visit_id(param.hir_id));
1042 match param.name {
1043 ParamName::Plain(ident) | ParamName::Error(ident) => try_visit!(visitor.visit_ident(ident)),
1044 ParamName::Fresh => {}
1045 }
1046 match param.kind {
1047 GenericParamKind::Lifetime { .. } => {}
1048 GenericParamKind::Type { ref default, .. } => {
1049 visit_opt!(visitor, visit_ty_unambig, default)
1050 }
1051 GenericParamKind::Const { ref ty, ref default, synthetic: _ } => {
1052 try_visit!(visitor.visit_ty_unambig(ty));
1053 if let Some(default) = default {
1054 try_visit!(visitor.visit_const_param_default(param.hir_id, default));
1055 }
1056 }
1057 }
1058 V::Result::output()
1059}
1060
1061pub fn walk_const_param_default<'v, V: Visitor<'v>>(
1062 visitor: &mut V,
1063 ct: &'v ConstArg<'v>,
1064) -> V::Result {
1065 visitor.visit_const_arg_unambig(ct)
1066}
1067
1068pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) -> V::Result {
1069 walk_list!(visitor, visit_generic_param, generics.params);
1070 walk_list!(visitor, visit_where_predicate, generics.predicates);
1071 V::Result::output()
1072}
1073
1074pub fn walk_where_predicate<'v, V: Visitor<'v>>(
1075 visitor: &mut V,
1076 predicate: &'v WherePredicate<'v>,
1077) -> V::Result {
1078 let &WherePredicate { hir_id, kind, span: _ } = predicate;
1079 try_visit!(visitor.visit_id(hir_id));
1080 match *kind {
1081 WherePredicateKind::BoundPredicate(WhereBoundPredicate {
1082 ref bounded_ty,
1083 bounds,
1084 bound_generic_params,
1085 origin: _,
1086 }) => {
1087 try_visit!(visitor.visit_ty_unambig(bounded_ty));
1088 walk_list!(visitor, visit_param_bound, bounds);
1089 walk_list!(visitor, visit_generic_param, bound_generic_params);
1090 }
1091 WherePredicateKind::RegionPredicate(WhereRegionPredicate {
1092 ref lifetime,
1093 bounds,
1094 in_where_clause: _,
1095 }) => {
1096 try_visit!(visitor.visit_lifetime(lifetime));
1097 walk_list!(visitor, visit_param_bound, bounds);
1098 }
1099 WherePredicateKind::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty }) => {
1100 try_visit!(visitor.visit_ty_unambig(lhs_ty));
1101 try_visit!(visitor.visit_ty_unambig(rhs_ty));
1102 }
1103 }
1104 V::Result::output()
1105}
1106
1107pub fn walk_fn_decl<'v, V: Visitor<'v>>(
1108 visitor: &mut V,
1109 function_declaration: &'v FnDecl<'v>,
1110) -> V::Result {
1111 walk_list!(visitor, visit_ty_unambig, function_declaration.inputs);
1112 visitor.visit_fn_ret_ty(&function_declaration.output)
1113}
1114
1115pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) -> V::Result {
1116 if let FnRetTy::Return(output_ty) = *ret_ty {
1117 try_visit!(visitor.visit_ty_unambig(output_ty));
1118 }
1119 V::Result::output()
1120}
1121
1122pub fn walk_fn<'v, V: Visitor<'v>>(
1123 visitor: &mut V,
1124 function_kind: FnKind<'v>,
1125 function_declaration: &'v FnDecl<'v>,
1126 body_id: BodyId,
1127 _: LocalDefId,
1128) -> V::Result {
1129 try_visit!(visitor.visit_fn_decl(function_declaration));
1130 try_visit!(walk_fn_kind(visitor, function_kind));
1131 visitor.visit_nested_body(body_id)
1132}
1133
1134pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) -> V::Result {
1135 match function_kind {
1136 FnKind::ItemFn(_, generics, ..) => {
1137 try_visit!(visitor.visit_generics(generics));
1138 }
1139 FnKind::Closure | FnKind::Method(..) => {}
1140 }
1141 V::Result::output()
1142}
1143
1144pub fn walk_use<'v, V: Visitor<'v>>(
1145 visitor: &mut V,
1146 path: &'v UsePath<'v>,
1147 hir_id: HirId,
1148) -> V::Result {
1149 let UsePath { segments, ref res, span } = *path;
1150 for &res in res {
1151 try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id));
1152 }
1153 V::Result::output()
1154}
1155
1156pub fn walk_trait_item<'v, V: Visitor<'v>>(
1157 visitor: &mut V,
1158 trait_item: &'v TraitItem<'v>,
1159) -> V::Result {
1160 let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
1162 let hir_id = trait_item.hir_id();
1163 try_visit!(visitor.visit_ident(ident));
1164 try_visit!(visitor.visit_generics(&generics));
1165 try_visit!(visitor.visit_defaultness(&defaultness));
1166 try_visit!(visitor.visit_id(hir_id));
1167 match *kind {
1168 TraitItemKind::Const(ref ty, default) => {
1169 try_visit!(visitor.visit_ty_unambig(ty));
1170 visit_opt!(visitor, visit_nested_body, default);
1171 }
1172 TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
1173 try_visit!(visitor.visit_fn_decl(sig.decl));
1174 for ident in param_names.iter().copied() {
1175 visit_opt!(visitor, visit_ident, ident);
1176 }
1177 }
1178 TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
1179 try_visit!(visitor.visit_fn(
1180 FnKind::Method(ident, sig),
1181 sig.decl,
1182 body_id,
1183 span,
1184 trait_item.owner_id.def_id,
1185 ));
1186 }
1187 TraitItemKind::Type(bounds, ref default) => {
1188 walk_list!(visitor, visit_param_bound, bounds);
1189 visit_opt!(visitor, visit_ty_unambig, default);
1190 }
1191 }
1192 V::Result::output()
1193}
1194
1195pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(
1196 visitor: &mut V,
1197 trait_item_ref: &'v TraitItemRef,
1198) -> V::Result {
1199 let TraitItemRef { id, ident, ref kind, span: _ } = *trait_item_ref;
1201 try_visit!(visitor.visit_nested_trait_item(id));
1202 try_visit!(visitor.visit_ident(ident));
1203 visitor.visit_associated_item_kind(kind)
1204}
1205
1206pub fn walk_impl_item<'v, V: Visitor<'v>>(
1207 visitor: &mut V,
1208 impl_item: &'v ImplItem<'v>,
1209) -> V::Result {
1210 let ImplItem {
1212 owner_id: _,
1213 ident,
1214 ref generics,
1215 ref kind,
1216 ref defaultness,
1217 span: _,
1218 vis_span: _,
1219 } = *impl_item;
1220
1221 try_visit!(visitor.visit_ident(ident));
1222 try_visit!(visitor.visit_generics(generics));
1223 try_visit!(visitor.visit_defaultness(defaultness));
1224 try_visit!(visitor.visit_id(impl_item.hir_id()));
1225 match *kind {
1226 ImplItemKind::Const(ref ty, body) => {
1227 try_visit!(visitor.visit_ty_unambig(ty));
1228 visitor.visit_nested_body(body)
1229 }
1230 ImplItemKind::Fn(ref sig, body_id) => visitor.visit_fn(
1231 FnKind::Method(impl_item.ident, sig),
1232 sig.decl,
1233 body_id,
1234 impl_item.span,
1235 impl_item.owner_id.def_id,
1236 ),
1237 ImplItemKind::Type(ref ty) => visitor.visit_ty_unambig(ty),
1238 }
1239}
1240
1241pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(
1242 visitor: &mut V,
1243 foreign_item_ref: &'v ForeignItemRef,
1244) -> V::Result {
1245 let ForeignItemRef { id, ident, span: _ } = *foreign_item_ref;
1247 try_visit!(visitor.visit_nested_foreign_item(id));
1248 visitor.visit_ident(ident)
1249}
1250
1251pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(
1252 visitor: &mut V,
1253 impl_item_ref: &'v ImplItemRef,
1254) -> V::Result {
1255 let ImplItemRef { id, ident, ref kind, span: _, trait_item_def_id: _ } = *impl_item_ref;
1257 try_visit!(visitor.visit_nested_impl_item(id));
1258 try_visit!(visitor.visit_ident(ident));
1259 visitor.visit_associated_item_kind(kind)
1260}
1261
1262pub fn walk_trait_ref<'v, V: Visitor<'v>>(
1263 visitor: &mut V,
1264 trait_ref: &'v TraitRef<'v>,
1265) -> V::Result {
1266 try_visit!(visitor.visit_id(trait_ref.hir_ref_id));
1267 visitor.visit_path(trait_ref.path, trait_ref.hir_ref_id)
1268}
1269
1270pub fn walk_param_bound<'v, V: Visitor<'v>>(
1271 visitor: &mut V,
1272 bound: &'v GenericBound<'v>,
1273) -> V::Result {
1274 match *bound {
1275 GenericBound::Trait(ref typ) => visitor.visit_poly_trait_ref(typ),
1276 GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
1277 GenericBound::Use(args, _) => {
1278 walk_list!(visitor, visit_precise_capturing_arg, args);
1279 V::Result::output()
1280 }
1281 }
1282}
1283
1284pub fn walk_precise_capturing_arg<'v, V: Visitor<'v>>(
1285 visitor: &mut V,
1286 arg: &'v PreciseCapturingArg<'v>,
1287) -> V::Result {
1288 match *arg {
1289 PreciseCapturingArg::Lifetime(lt) => visitor.visit_lifetime(lt),
1290 PreciseCapturingArg::Param(param) => visitor.visit_id(param.hir_id),
1291 }
1292}
1293
1294pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
1295 visitor: &mut V,
1296 trait_ref: &'v PolyTraitRef<'v>,
1297) -> V::Result {
1298 walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
1299 visitor.visit_trait_ref(&trait_ref.trait_ref)
1300}
1301
1302pub fn walk_opaque_ty<'v, V: Visitor<'v>>(visitor: &mut V, opaque: &'v OpaqueTy<'v>) -> V::Result {
1303 let &OpaqueTy { hir_id, def_id: _, bounds, origin: _, span: _ } = opaque;
1304 try_visit!(visitor.visit_id(hir_id));
1305 walk_list!(visitor, visit_param_bound, bounds);
1306 V::Result::output()
1307}
1308
1309pub fn walk_struct_def<'v, V: Visitor<'v>>(
1310 visitor: &mut V,
1311 struct_definition: &'v VariantData<'v>,
1312) -> V::Result {
1313 visit_opt!(visitor, visit_id, struct_definition.ctor_hir_id());
1314 walk_list!(visitor, visit_field_def, struct_definition.fields());
1315 V::Result::output()
1316}
1317
1318pub fn walk_field_def<'v, V: Visitor<'v>>(
1319 visitor: &mut V,
1320 FieldDef { hir_id, ident, ty, default, span: _, vis_span: _, def_id: _, safety: _ }: &'v FieldDef<'v>,
1321) -> V::Result {
1322 try_visit!(visitor.visit_id(*hir_id));
1323 try_visit!(visitor.visit_ident(*ident));
1324 visit_opt!(visitor, visit_anon_const, default);
1325 visitor.visit_ty_unambig(*ty)
1326}
1327
1328pub fn walk_enum_def<'v, V: Visitor<'v>>(
1329 visitor: &mut V,
1330 enum_definition: &'v EnumDef<'v>,
1331) -> V::Result {
1332 walk_list!(visitor, visit_variant, enum_definition.variants);
1333 V::Result::output()
1334}
1335
1336pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) -> V::Result {
1337 try_visit!(visitor.visit_ident(variant.ident));
1338 try_visit!(visitor.visit_id(variant.hir_id));
1339 try_visit!(visitor.visit_variant_data(&variant.data));
1340 visit_opt!(visitor, visit_anon_const, &variant.disr_expr);
1341 V::Result::output()
1342}
1343
1344pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) -> V::Result {
1345 visitor.visit_ident(label.ident)
1346}
1347
1348pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) -> V::Result {
1349 visitor.visit_id(inf.hir_id)
1350}
1351
1352pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) -> V::Result {
1353 try_visit!(visitor.visit_id(lifetime.hir_id));
1354 visitor.visit_ident(lifetime.ident)
1355}
1356
1357pub fn walk_qpath<'v, V: Visitor<'v>>(
1358 visitor: &mut V,
1359 qpath: &'v QPath<'v>,
1360 id: HirId,
1361) -> V::Result {
1362 match *qpath {
1363 QPath::Resolved(ref maybe_qself, ref path) => {
1364 visit_opt!(visitor, visit_ty_unambig, maybe_qself);
1365 visitor.visit_path(path, id)
1366 }
1367 QPath::TypeRelative(ref qself, ref segment) => {
1368 try_visit!(visitor.visit_ty_unambig(qself));
1369 visitor.visit_path_segment(segment)
1370 }
1371 QPath::LangItem(..) => V::Result::output(),
1372 }
1373}
1374
1375pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &Path<'v>) -> V::Result {
1376 walk_list!(visitor, visit_path_segment, path.segments);
1377 V::Result::output()
1378}
1379
1380pub fn walk_path_segment<'v, V: Visitor<'v>>(
1381 visitor: &mut V,
1382 segment: &'v PathSegment<'v>,
1383) -> V::Result {
1384 try_visit!(visitor.visit_ident(segment.ident));
1385 try_visit!(visitor.visit_id(segment.hir_id));
1386 visit_opt!(visitor, visit_generic_args, segment.args);
1387 V::Result::output()
1388}
1389
1390pub fn walk_generic_args<'v, V: Visitor<'v>>(
1391 visitor: &mut V,
1392 generic_args: &'v GenericArgs<'v>,
1393) -> V::Result {
1394 walk_list!(visitor, visit_generic_arg, generic_args.args);
1395 walk_list!(visitor, visit_assoc_item_constraint, generic_args.constraints);
1396 V::Result::output()
1397}
1398
1399pub fn walk_assoc_item_constraint<'v, V: Visitor<'v>>(
1400 visitor: &mut V,
1401 constraint: &'v AssocItemConstraint<'v>,
1402) -> V::Result {
1403 try_visit!(visitor.visit_id(constraint.hir_id));
1404 try_visit!(visitor.visit_ident(constraint.ident));
1405 try_visit!(visitor.visit_generic_args(constraint.gen_args));
1406 match constraint.kind {
1407 AssocItemConstraintKind::Equality { ref term } => match term {
1408 Term::Ty(ty) => try_visit!(visitor.visit_ty_unambig(ty)),
1409 Term::Const(c) => try_visit!(visitor.visit_const_arg_unambig(c)),
1410 },
1411 AssocItemConstraintKind::Bound { bounds } => {
1412 walk_list!(visitor, visit_param_bound, bounds)
1413 }
1414 }
1415 V::Result::output()
1416}
1417
1418pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) -> V::Result {
1419 V::Result::output()
1423}
1424
1425pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) -> V::Result {
1426 V::Result::output()
1430}
1431
1432pub fn walk_inline_asm<'v, V: Visitor<'v>>(
1433 visitor: &mut V,
1434 asm: &'v InlineAsm<'v>,
1435 id: HirId,
1436) -> V::Result {
1437 for (op, op_sp) in asm.operands {
1438 match op {
1439 InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
1440 try_visit!(visitor.visit_expr(expr));
1441 }
1442 InlineAsmOperand::Out { expr, .. } => {
1443 visit_opt!(visitor, visit_expr, expr);
1444 }
1445 InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1446 try_visit!(visitor.visit_expr(in_expr));
1447 visit_opt!(visitor, visit_expr, out_expr);
1448 }
1449 InlineAsmOperand::Const { anon_const, .. } => {
1450 try_visit!(visitor.visit_inline_const(anon_const));
1451 }
1452 InlineAsmOperand::SymFn { expr, .. } => {
1453 try_visit!(visitor.visit_expr(expr));
1454 }
1455 InlineAsmOperand::SymStatic { path, .. } => {
1456 try_visit!(visitor.visit_qpath(path, id, *op_sp));
1457 }
1458 InlineAsmOperand::Label { block } => try_visit!(visitor.visit_block(block)),
1459 }
1460 }
1461 V::Result::output()
1462}