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::ConstBlock(c) => visitor.visit_inline_const(c),
796 PatExprKind::Path(qpath) => visitor.visit_qpath(qpath, *hir_id, *span),
797 }
798}
799
800pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) -> V::Result {
801 let AnonConst { hir_id, def_id: _, body, span: _ } = constant;
802 try_visit!(visitor.visit_id(*hir_id));
803 visitor.visit_nested_body(*body)
804}
805
806pub fn walk_inline_const<'v, V: Visitor<'v>>(
807 visitor: &mut V,
808 constant: &'v ConstBlock,
809) -> V::Result {
810 let ConstBlock { hir_id, def_id: _, body } = constant;
811 try_visit!(visitor.visit_id(*hir_id));
812 visitor.visit_nested_body(*body)
813}
814
815pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) -> V::Result {
816 let Expr { hir_id, kind, span } = expression;
817 try_visit!(visitor.visit_id(*hir_id));
818 match *kind {
819 ExprKind::Array(subexpressions) => {
820 walk_list!(visitor, visit_expr, subexpressions);
821 }
822 ExprKind::ConstBlock(ref const_block) => {
823 try_visit!(visitor.visit_inline_const(const_block))
824 }
825 ExprKind::Repeat(ref element, ref count) => {
826 try_visit!(visitor.visit_expr(element));
827 try_visit!(visitor.visit_const_arg_unambig(count));
828 }
829 ExprKind::Struct(ref qpath, fields, ref optional_base) => {
830 try_visit!(visitor.visit_qpath(qpath, *hir_id, *span));
831 walk_list!(visitor, visit_expr_field, fields);
832 match optional_base {
833 StructTailExpr::Base(base) => try_visit!(visitor.visit_expr(base)),
834 StructTailExpr::None | StructTailExpr::DefaultFields(_) => {}
835 }
836 }
837 ExprKind::Tup(subexpressions) => {
838 walk_list!(visitor, visit_expr, subexpressions);
839 }
840 ExprKind::Call(ref callee_expression, arguments) => {
841 try_visit!(visitor.visit_expr(callee_expression));
842 walk_list!(visitor, visit_expr, arguments);
843 }
844 ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
845 try_visit!(visitor.visit_path_segment(segment));
846 try_visit!(visitor.visit_expr(receiver));
847 walk_list!(visitor, visit_expr, arguments);
848 }
849 ExprKind::Use(expr, _) => {
850 try_visit!(visitor.visit_expr(expr));
851 }
852 ExprKind::Binary(_, ref left_expression, ref right_expression) => {
853 try_visit!(visitor.visit_expr(left_expression));
854 try_visit!(visitor.visit_expr(right_expression));
855 }
856 ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
857 try_visit!(visitor.visit_expr(subexpression));
858 }
859 ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
860 try_visit!(visitor.visit_expr(subexpression));
861 try_visit!(visitor.visit_ty_unambig(typ));
862 }
863 ExprKind::DropTemps(ref subexpression) => {
864 try_visit!(visitor.visit_expr(subexpression));
865 }
866 ExprKind::Let(LetExpr { span: _, pat, ty, init, recovered: _ }) => {
867 try_visit!(visitor.visit_expr(init));
869 try_visit!(visitor.visit_pat(pat));
870 visit_opt!(visitor, visit_ty_unambig, ty);
871 }
872 ExprKind::If(ref cond, ref then, ref else_opt) => {
873 try_visit!(visitor.visit_expr(cond));
874 try_visit!(visitor.visit_expr(then));
875 visit_opt!(visitor, visit_expr, else_opt);
876 }
877 ExprKind::Loop(ref block, ref opt_label, _, _) => {
878 visit_opt!(visitor, visit_label, opt_label);
879 try_visit!(visitor.visit_block(block));
880 }
881 ExprKind::Match(ref subexpression, arms, _) => {
882 try_visit!(visitor.visit_expr(subexpression));
883 walk_list!(visitor, visit_arm, arms);
884 }
885 ExprKind::Closure(&Closure {
886 def_id,
887 binder: _,
888 bound_generic_params,
889 fn_decl,
890 body,
891 capture_clause: _,
892 fn_decl_span: _,
893 fn_arg_span: _,
894 kind: _,
895 constness: _,
896 }) => {
897 walk_list!(visitor, visit_generic_param, bound_generic_params);
898 try_visit!(visitor.visit_fn(FnKind::Closure, fn_decl, body, *span, def_id));
899 }
900 ExprKind::Block(ref block, ref opt_label) => {
901 visit_opt!(visitor, visit_label, opt_label);
902 try_visit!(visitor.visit_block(block));
903 }
904 ExprKind::Assign(ref lhs, ref rhs, _) => {
905 try_visit!(visitor.visit_expr(rhs));
906 try_visit!(visitor.visit_expr(lhs));
907 }
908 ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
909 try_visit!(visitor.visit_expr(right_expression));
910 try_visit!(visitor.visit_expr(left_expression));
911 }
912 ExprKind::Field(ref subexpression, ident) => {
913 try_visit!(visitor.visit_expr(subexpression));
914 try_visit!(visitor.visit_ident(ident));
915 }
916 ExprKind::Index(ref main_expression, ref index_expression, _) => {
917 try_visit!(visitor.visit_expr(main_expression));
918 try_visit!(visitor.visit_expr(index_expression));
919 }
920 ExprKind::Path(ref qpath) => {
921 try_visit!(visitor.visit_qpath(qpath, *hir_id, *span));
922 }
923 ExprKind::Break(ref destination, ref opt_expr) => {
924 visit_opt!(visitor, visit_label, &destination.label);
925 visit_opt!(visitor, visit_expr, opt_expr);
926 }
927 ExprKind::Continue(ref destination) => {
928 visit_opt!(visitor, visit_label, &destination.label);
929 }
930 ExprKind::Ret(ref optional_expression) => {
931 visit_opt!(visitor, visit_expr, optional_expression);
932 }
933 ExprKind::Become(ref expr) => try_visit!(visitor.visit_expr(expr)),
934 ExprKind::InlineAsm(ref asm) => {
935 try_visit!(visitor.visit_inline_asm(asm, *hir_id));
936 }
937 ExprKind::OffsetOf(ref container, ref fields) => {
938 try_visit!(visitor.visit_ty_unambig(container));
939 walk_list!(visitor, visit_ident, fields.iter().copied());
940 }
941 ExprKind::Yield(ref subexpression, _) => {
942 try_visit!(visitor.visit_expr(subexpression));
943 }
944 ExprKind::UnsafeBinderCast(_kind, expr, ty) => {
945 try_visit!(visitor.visit_expr(expr));
946 visit_opt!(visitor, visit_ty_unambig, ty);
947 }
948 ExprKind::Lit(lit) => try_visit!(visitor.visit_lit(*hir_id, lit, false)),
949 ExprKind::Err(_) => {}
950 }
951 V::Result::output()
952}
953
954pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) -> V::Result {
955 let ExprField { hir_id, ident, expr, span: _, is_shorthand: _ } = field;
956 try_visit!(visitor.visit_id(*hir_id));
957 try_visit!(visitor.visit_ident(*ident));
958 visitor.visit_expr(*expr)
959}
960
961pub fn walk_const_arg_expr_field<'v, V: Visitor<'v>>(
962 visitor: &mut V,
963 field: &'v ConstArgExprField<'v>,
964) -> V::Result {
965 let ConstArgExprField { hir_id, field, expr, span: _ } = field;
966 try_visit!(visitor.visit_id(*hir_id));
967 try_visit!(visitor.visit_ident(*field));
968 visitor.visit_const_arg_unambig(*expr)
969}
970
971pub enum InferKind<'hir> {
974 Ty(&'hir Ty<'hir>),
975 Const(&'hir ConstArg<'hir>),
976 Ambig(&'hir InferArg),
977}
978
979pub fn walk_generic_arg<'v, V: Visitor<'v>>(
980 visitor: &mut V,
981 generic_arg: &'v GenericArg<'v>,
982) -> V::Result {
983 match generic_arg {
984 GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
985 GenericArg::Type(ty) => visitor.visit_ty(ty),
986 GenericArg::Const(ct) => visitor.visit_const_arg(ct),
987 GenericArg::Infer(inf) => {
988 let InferArg { hir_id, span } = inf;
989 visitor.visit_infer(*hir_id, *span, InferKind::Ambig(inf))
990 }
991 }
992}
993
994pub fn walk_unambig_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) -> V::Result {
995 match typ.try_as_ambig_ty() {
996 Some(ambig_ty) => visitor.visit_ty(ambig_ty),
997 None => {
998 let Ty { hir_id, span, kind: _ } = typ;
999 visitor.visit_infer(*hir_id, *span, InferKind::Ty(typ))
1000 }
1001 }
1002}
1003
1004pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -> V::Result {
1005 let Ty { hir_id, span: _, kind } = typ;
1006 try_visit!(visitor.visit_id(*hir_id));
1007
1008 match *kind {
1009 TyKind::Slice(ref ty) => try_visit!(visitor.visit_ty_unambig(ty)),
1010 TyKind::Ptr(ref mutable_type) => try_visit!(visitor.visit_ty_unambig(mutable_type.ty)),
1011 TyKind::Ref(ref lifetime, ref mutable_type) => {
1012 try_visit!(visitor.visit_lifetime(lifetime));
1013 try_visit!(visitor.visit_ty_unambig(mutable_type.ty));
1014 }
1015 TyKind::Never => {}
1016 TyKind::Tup(tuple_element_types) => {
1017 walk_list!(visitor, visit_ty_unambig, tuple_element_types);
1018 }
1019 TyKind::FnPtr(ref function_declaration) => {
1020 walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
1021 try_visit!(visitor.visit_fn_decl(function_declaration.decl));
1022 }
1023 TyKind::UnsafeBinder(ref unsafe_binder) => {
1024 walk_list!(visitor, visit_generic_param, unsafe_binder.generic_params);
1025 try_visit!(visitor.visit_ty_unambig(unsafe_binder.inner_ty));
1026 }
1027 TyKind::Path(ref qpath) => {
1028 try_visit!(visitor.visit_qpath(qpath, typ.hir_id, typ.span));
1029 }
1030 TyKind::OpaqueDef(opaque) => {
1031 try_visit!(visitor.visit_opaque_ty(opaque));
1032 }
1033 TyKind::TraitAscription(bounds) => {
1034 walk_list!(visitor, visit_param_bound, bounds);
1035 }
1036 TyKind::Array(ref ty, ref length) => {
1037 try_visit!(visitor.visit_ty_unambig(ty));
1038 try_visit!(visitor.visit_const_arg_unambig(length));
1039 }
1040 TyKind::TraitObject(bounds, ref lifetime) => {
1041 for bound in bounds {
1042 try_visit!(visitor.visit_poly_trait_ref(bound));
1043 }
1044 try_visit!(visitor.visit_lifetime(lifetime));
1045 }
1046 TyKind::InferDelegation(..) | TyKind::Err(_) => {}
1047 TyKind::Pat(ty, pat) => {
1048 try_visit!(visitor.visit_ty_unambig(ty));
1049 try_visit!(visitor.visit_pattern_type_pattern(pat));
1050 }
1051 }
1052 V::Result::output()
1053}
1054
1055pub fn walk_const_item_rhs<'v, V: Visitor<'v>>(
1056 visitor: &mut V,
1057 ct_rhs: ConstItemRhs<'v>,
1058) -> V::Result {
1059 match ct_rhs {
1060 ConstItemRhs::Body(body_id) => visitor.visit_nested_body(body_id),
1061 ConstItemRhs::TypeConst(const_arg) => visitor.visit_const_arg_unambig(const_arg),
1062 }
1063}
1064
1065pub fn walk_unambig_const_arg<'v, V: Visitor<'v>>(
1066 visitor: &mut V,
1067 const_arg: &'v ConstArg<'v>,
1068) -> V::Result {
1069 match const_arg.try_as_ambig_ct() {
1070 Some(ambig_ct) => visitor.visit_const_arg(ambig_ct),
1071 None => {
1072 let ConstArg { hir_id, kind: _ } = const_arg;
1073 visitor.visit_infer(*hir_id, const_arg.span(), InferKind::Const(const_arg))
1074 }
1075 }
1076}
1077
1078pub fn walk_const_arg<'v, V: Visitor<'v>>(
1079 visitor: &mut V,
1080 const_arg: &'v ConstArg<'v, AmbigArg>,
1081) -> V::Result {
1082 let ConstArg { hir_id, kind } = const_arg;
1083 try_visit!(visitor.visit_id(*hir_id));
1084 match kind {
1085 ConstArgKind::Struct(qpath, field_exprs) => {
1086 try_visit!(visitor.visit_qpath(qpath, *hir_id, qpath.span()));
1087
1088 for field_expr in *field_exprs {
1089 try_visit!(visitor.visit_const_arg_expr_field(field_expr));
1090 }
1091
1092 V::Result::output()
1093 }
1094 ConstArgKind::Path(qpath) => visitor.visit_qpath(qpath, *hir_id, qpath.span()),
1095 ConstArgKind::Anon(anon) => visitor.visit_anon_const(*anon),
1096 ConstArgKind::Error(_, _) => V::Result::output(), }
1098}
1099
1100pub fn walk_generic_param<'v, V: Visitor<'v>>(
1101 visitor: &mut V,
1102 param: &'v GenericParam<'v>,
1103) -> V::Result {
1104 let GenericParam {
1105 hir_id,
1106 def_id: _,
1107 name,
1108 span: _,
1109 pure_wrt_drop: _,
1110 kind,
1111 colon_span: _,
1112 source: _,
1113 } = param;
1114 try_visit!(visitor.visit_id(*hir_id));
1115 match *name {
1116 ParamName::Plain(ident) | ParamName::Error(ident) => try_visit!(visitor.visit_ident(ident)),
1117 ParamName::Fresh => {}
1118 }
1119 match *kind {
1120 GenericParamKind::Lifetime { .. } => {}
1121 GenericParamKind::Type { ref default, .. } => {
1122 visit_opt!(visitor, visit_ty_unambig, default)
1123 }
1124 GenericParamKind::Const { ref ty, ref default } => {
1125 try_visit!(visitor.visit_ty_unambig(ty));
1126 if let Some(default) = default {
1127 try_visit!(visitor.visit_const_param_default(*hir_id, default));
1128 }
1129 }
1130 }
1131 V::Result::output()
1132}
1133
1134pub fn walk_const_param_default<'v, V: Visitor<'v>>(
1135 visitor: &mut V,
1136 ct: &'v ConstArg<'v>,
1137) -> V::Result {
1138 visitor.visit_const_arg_unambig(ct)
1139}
1140
1141pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics<'v>) -> V::Result {
1142 let &Generics {
1143 params,
1144 predicates,
1145 has_where_clause_predicates: _,
1146 where_clause_span: _,
1147 span: _,
1148 } = generics;
1149 walk_list!(visitor, visit_generic_param, params);
1150 walk_list!(visitor, visit_where_predicate, predicates);
1151 V::Result::output()
1152}
1153
1154pub fn walk_where_predicate<'v, V: Visitor<'v>>(
1155 visitor: &mut V,
1156 predicate: &'v WherePredicate<'v>,
1157) -> V::Result {
1158 let &WherePredicate { hir_id, kind, span: _ } = predicate;
1159 try_visit!(visitor.visit_id(hir_id));
1160 match *kind {
1161 WherePredicateKind::BoundPredicate(WhereBoundPredicate {
1162 ref bounded_ty,
1163 bounds,
1164 bound_generic_params,
1165 origin: _,
1166 }) => {
1167 try_visit!(visitor.visit_ty_unambig(bounded_ty));
1168 walk_list!(visitor, visit_param_bound, bounds);
1169 walk_list!(visitor, visit_generic_param, bound_generic_params);
1170 }
1171 WherePredicateKind::RegionPredicate(WhereRegionPredicate {
1172 ref lifetime,
1173 bounds,
1174 in_where_clause: _,
1175 }) => {
1176 try_visit!(visitor.visit_lifetime(lifetime));
1177 walk_list!(visitor, visit_param_bound, bounds);
1178 }
1179 WherePredicateKind::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty }) => {
1180 try_visit!(visitor.visit_ty_unambig(lhs_ty));
1181 try_visit!(visitor.visit_ty_unambig(rhs_ty));
1182 }
1183 }
1184 V::Result::output()
1185}
1186
1187pub fn walk_fn_decl<'v, V: Visitor<'v>>(
1188 visitor: &mut V,
1189 function_declaration: &'v FnDecl<'v>,
1190) -> V::Result {
1191 let FnDecl { inputs, output, c_variadic: _, implicit_self: _, lifetime_elision_allowed: _ } =
1192 function_declaration;
1193 walk_list!(visitor, visit_ty_unambig, *inputs);
1194 visitor.visit_fn_ret_ty(output)
1195}
1196
1197pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) -> V::Result {
1198 if let FnRetTy::Return(output_ty) = *ret_ty {
1199 try_visit!(visitor.visit_ty_unambig(output_ty));
1200 }
1201 V::Result::output()
1202}
1203
1204pub fn walk_fn<'v, V: Visitor<'v>>(
1205 visitor: &mut V,
1206 function_kind: FnKind<'v>,
1207 function_declaration: &'v FnDecl<'v>,
1208 body_id: BodyId,
1209 _: LocalDefId,
1210) -> V::Result {
1211 try_visit!(visitor.visit_fn_decl(function_declaration));
1212 try_visit!(walk_fn_kind(visitor, function_kind));
1213 visitor.visit_nested_body(body_id)
1214}
1215
1216pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) -> V::Result {
1217 match function_kind {
1218 FnKind::ItemFn(_, generics, ..) => {
1219 try_visit!(visitor.visit_generics(generics));
1220 }
1221 FnKind::Closure | FnKind::Method(..) => {}
1222 }
1223 V::Result::output()
1224}
1225
1226pub fn walk_use<'v, V: Visitor<'v>>(
1227 visitor: &mut V,
1228 path: &'v UsePath<'v>,
1229 hir_id: HirId,
1230) -> V::Result {
1231 let UsePath { segments, ref res, span } = *path;
1232 for res in res.present_items() {
1233 try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id));
1234 }
1235 V::Result::output()
1236}
1237
1238pub fn walk_trait_item<'v, V: Visitor<'v>>(
1239 visitor: &mut V,
1240 trait_item: &'v TraitItem<'v>,
1241) -> V::Result {
1242 let TraitItem {
1243 ident,
1244 generics,
1245 ref defaultness,
1246 ref kind,
1247 span,
1248 owner_id: _,
1249 has_delayed_lints: _,
1250 } = *trait_item;
1251 let hir_id = trait_item.hir_id();
1252 try_visit!(visitor.visit_ident(ident));
1253 try_visit!(visitor.visit_generics(&generics));
1254 try_visit!(visitor.visit_defaultness(&defaultness));
1255 try_visit!(visitor.visit_id(hir_id));
1256 match *kind {
1257 TraitItemKind::Const(ref ty, default) => {
1258 try_visit!(visitor.visit_ty_unambig(ty));
1259 visit_opt!(visitor, visit_const_item_rhs, default);
1260 }
1261 TraitItemKind::Fn(ref sig, TraitFn::Required(param_idents)) => {
1262 try_visit!(visitor.visit_fn_decl(sig.decl));
1263 for ident in param_idents.iter().copied() {
1264 visit_opt!(visitor, visit_ident, ident);
1265 }
1266 }
1267 TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
1268 try_visit!(visitor.visit_fn(
1269 FnKind::Method(ident, sig),
1270 sig.decl,
1271 body_id,
1272 span,
1273 trait_item.owner_id.def_id,
1274 ));
1275 }
1276 TraitItemKind::Type(bounds, ref default) => {
1277 walk_list!(visitor, visit_param_bound, bounds);
1278 visit_opt!(visitor, visit_ty_unambig, default);
1279 }
1280 }
1281 V::Result::output()
1282}
1283
1284pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: TraitItemId) -> V::Result {
1285 visitor.visit_nested_trait_item(id)
1286}
1287
1288pub fn walk_impl_item<'v, V: Visitor<'v>>(
1289 visitor: &mut V,
1290 impl_item: &'v ImplItem<'v>,
1291) -> V::Result {
1292 let ImplItem {
1293 owner_id: _,
1294 ident,
1295 ref generics,
1296 ref impl_kind,
1297 ref kind,
1298 span: _,
1299 has_delayed_lints: _,
1300 } = *impl_item;
1301
1302 try_visit!(visitor.visit_ident(ident));
1303 try_visit!(visitor.visit_generics(generics));
1304 try_visit!(visitor.visit_id(impl_item.hir_id()));
1305 match impl_kind {
1306 ImplItemImplKind::Inherent { vis_span: _ } => {}
1307 ImplItemImplKind::Trait { defaultness, trait_item_def_id: _ } => {
1308 try_visit!(visitor.visit_defaultness(defaultness));
1309 }
1310 }
1311 match *kind {
1312 ImplItemKind::Const(ref ty, rhs) => {
1313 try_visit!(visitor.visit_ty_unambig(ty));
1314 visitor.visit_const_item_rhs(rhs)
1315 }
1316 ImplItemKind::Fn(ref sig, body_id) => visitor.visit_fn(
1317 FnKind::Method(impl_item.ident, sig),
1318 sig.decl,
1319 body_id,
1320 impl_item.span,
1321 impl_item.owner_id.def_id,
1322 ),
1323 ImplItemKind::Type(ref ty) => visitor.visit_ty_unambig(ty),
1324 }
1325}
1326
1327pub fn walk_foreign_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: ForeignItemId) -> V::Result {
1328 visitor.visit_nested_foreign_item(id)
1329}
1330
1331pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, id: ImplItemId) -> V::Result {
1332 visitor.visit_nested_impl_item(id)
1333}
1334
1335pub fn walk_trait_ref<'v, V: Visitor<'v>>(
1336 visitor: &mut V,
1337 trait_ref: &'v TraitRef<'v>,
1338) -> V::Result {
1339 let TraitRef { hir_ref_id, path } = trait_ref;
1340 try_visit!(visitor.visit_id(*hir_ref_id));
1341 visitor.visit_path(*path, *hir_ref_id)
1342}
1343
1344pub fn walk_param_bound<'v, V: Visitor<'v>>(
1345 visitor: &mut V,
1346 bound: &'v GenericBound<'v>,
1347) -> V::Result {
1348 match *bound {
1349 GenericBound::Trait(ref typ) => visitor.visit_poly_trait_ref(typ),
1350 GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
1351 GenericBound::Use(args, _) => {
1352 walk_list!(visitor, visit_precise_capturing_arg, args);
1353 V::Result::output()
1354 }
1355 }
1356}
1357
1358pub fn walk_precise_capturing_arg<'v, V: Visitor<'v>>(
1359 visitor: &mut V,
1360 arg: &'v PreciseCapturingArg<'v>,
1361) -> V::Result {
1362 match *arg {
1363 PreciseCapturingArg::Lifetime(lt) => visitor.visit_lifetime(lt),
1364 PreciseCapturingArg::Param(param) => {
1365 let PreciseCapturingNonLifetimeArg { hir_id, ident, res: _ } = param;
1366 try_visit!(visitor.visit_id(hir_id));
1367 visitor.visit_ident(ident)
1368 }
1369 }
1370}
1371
1372pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
1373 visitor: &mut V,
1374 trait_ref: &'v PolyTraitRef<'v>,
1375) -> V::Result {
1376 let PolyTraitRef { bound_generic_params, modifiers: _, trait_ref, span: _ } = trait_ref;
1377 walk_list!(visitor, visit_generic_param, *bound_generic_params);
1378 visitor.visit_trait_ref(trait_ref)
1379}
1380
1381pub fn walk_opaque_ty<'v, V: Visitor<'v>>(visitor: &mut V, opaque: &'v OpaqueTy<'v>) -> V::Result {
1382 let &OpaqueTy { hir_id, def_id: _, bounds, origin: _, span: _ } = opaque;
1383 try_visit!(visitor.visit_id(hir_id));
1384 walk_list!(visitor, visit_param_bound, bounds);
1385 V::Result::output()
1386}
1387
1388pub fn walk_struct_def<'v, V: Visitor<'v>>(
1389 visitor: &mut V,
1390 struct_definition: &'v VariantData<'v>,
1391) -> V::Result {
1392 visit_opt!(visitor, visit_id, struct_definition.ctor_hir_id());
1393 walk_list!(visitor, visit_field_def, struct_definition.fields());
1394 V::Result::output()
1395}
1396
1397pub fn walk_field_def<'v, V: Visitor<'v>>(
1398 visitor: &mut V,
1399 FieldDef { hir_id, ident, ty, default, span: _, vis_span: _, def_id: _, safety: _ }: &'v FieldDef<'v>,
1400) -> V::Result {
1401 try_visit!(visitor.visit_id(*hir_id));
1402 try_visit!(visitor.visit_ident(*ident));
1403 visit_opt!(visitor, visit_anon_const, default);
1404 visitor.visit_ty_unambig(*ty)
1405}
1406
1407pub fn walk_enum_def<'v, V: Visitor<'v>>(
1408 visitor: &mut V,
1409 enum_definition: &'v EnumDef<'v>,
1410) -> V::Result {
1411 let EnumDef { variants } = enum_definition;
1412 walk_list!(visitor, visit_variant, *variants);
1413 V::Result::output()
1414}
1415
1416pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) -> V::Result {
1417 let Variant { ident, hir_id, def_id: _, data, disr_expr, span: _ } = variant;
1418 try_visit!(visitor.visit_ident(*ident));
1419 try_visit!(visitor.visit_id(*hir_id));
1420 try_visit!(visitor.visit_variant_data(data));
1421 visit_opt!(visitor, visit_anon_const, disr_expr);
1422 V::Result::output()
1423}
1424
1425pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) -> V::Result {
1426 let Label { ident } = label;
1427 visitor.visit_ident(*ident)
1428}
1429
1430pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) -> V::Result {
1431 let InferArg { hir_id, span: _ } = inf;
1432 visitor.visit_id(*hir_id)
1433}
1434
1435pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) -> V::Result {
1436 let Lifetime { hir_id, ident, kind: _, source: _, syntax: _ } = lifetime;
1437 try_visit!(visitor.visit_id(*hir_id));
1438 visitor.visit_ident(*ident)
1439}
1440
1441pub fn walk_qpath<'v, V: Visitor<'v>>(
1442 visitor: &mut V,
1443 qpath: &'v QPath<'v>,
1444 id: HirId,
1445) -> V::Result {
1446 match *qpath {
1447 QPath::Resolved(ref maybe_qself, ref path) => {
1448 visit_opt!(visitor, visit_ty_unambig, maybe_qself);
1449 visitor.visit_path(path, id)
1450 }
1451 QPath::TypeRelative(ref qself, ref segment) => {
1452 try_visit!(visitor.visit_ty_unambig(qself));
1453 visitor.visit_path_segment(segment)
1454 }
1455 }
1456}
1457
1458pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &Path<'v>) -> V::Result {
1459 let Path { segments, span: _, res: _ } = path;
1460 walk_list!(visitor, visit_path_segment, *segments);
1461 V::Result::output()
1462}
1463
1464pub fn walk_path_segment<'v, V: Visitor<'v>>(
1465 visitor: &mut V,
1466 segment: &'v PathSegment<'v>,
1467) -> V::Result {
1468 let PathSegment { ident, hir_id, res: _, args, infer_args: _ } = segment;
1469 try_visit!(visitor.visit_ident(*ident));
1470 try_visit!(visitor.visit_id(*hir_id));
1471 visit_opt!(visitor, visit_generic_args, *args);
1472 V::Result::output()
1473}
1474
1475pub fn walk_generic_args<'v, V: Visitor<'v>>(
1476 visitor: &mut V,
1477 generic_args: &'v GenericArgs<'v>,
1478) -> V::Result {
1479 let GenericArgs { args, constraints, parenthesized: _, span_ext: _ } = generic_args;
1480 walk_list!(visitor, visit_generic_arg, *args);
1481 walk_list!(visitor, visit_assoc_item_constraint, *constraints);
1482 V::Result::output()
1483}
1484
1485pub fn walk_assoc_item_constraint<'v, V: Visitor<'v>>(
1486 visitor: &mut V,
1487 constraint: &'v AssocItemConstraint<'v>,
1488) -> V::Result {
1489 let AssocItemConstraint { hir_id, ident, gen_args, kind: _, span: _ } = constraint;
1490 try_visit!(visitor.visit_id(*hir_id));
1491 try_visit!(visitor.visit_ident(*ident));
1492 try_visit!(visitor.visit_generic_args(*gen_args));
1493 match constraint.kind {
1494 AssocItemConstraintKind::Equality { ref term } => match term {
1495 Term::Ty(ty) => try_visit!(visitor.visit_ty_unambig(ty)),
1496 Term::Const(c) => try_visit!(visitor.visit_const_arg_unambig(c)),
1497 },
1498 AssocItemConstraintKind::Bound { bounds } => {
1499 walk_list!(visitor, visit_param_bound, bounds)
1500 }
1501 }
1502 V::Result::output()
1503}
1504
1505pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) -> V::Result {
1506 V::Result::output()
1510}
1511
1512pub fn walk_inline_asm<'v, V: Visitor<'v>>(
1513 visitor: &mut V,
1514 asm: &'v InlineAsm<'v>,
1515 id: HirId,
1516) -> V::Result {
1517 for (op, op_sp) in asm.operands {
1518 match op {
1519 InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
1520 try_visit!(visitor.visit_expr(expr));
1521 }
1522 InlineAsmOperand::Out { expr, .. } => {
1523 visit_opt!(visitor, visit_expr, expr);
1524 }
1525 InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1526 try_visit!(visitor.visit_expr(in_expr));
1527 visit_opt!(visitor, visit_expr, out_expr);
1528 }
1529 InlineAsmOperand::Const { anon_const, .. } => {
1530 try_visit!(visitor.visit_inline_const(anon_const));
1531 }
1532 InlineAsmOperand::SymFn { expr, .. } => {
1533 try_visit!(visitor.visit_expr(expr));
1534 }
1535 InlineAsmOperand::SymStatic { path, .. } => {
1536 try_visit!(visitor.visit_qpath(path, id, *op_sp));
1537 }
1538 InlineAsmOperand::Label { block } => try_visit!(visitor.visit_block(block)),
1539 }
1540 }
1541 V::Result::output()
1542}