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