Skip to content

Commit e604327

Browse files
committedNov 1, 2022
Reorder walk_ functions in intravisit.rs
1 parent c493bae commit e604327

File tree

1 file changed

+363
-363
lines changed

1 file changed

+363
-363
lines changed
 

‎compiler/rustc_hir/src/intravisit.rs

+363-363
Original file line numberDiff line numberDiff line change
@@ -443,72 +443,6 @@ pub trait Visitor<'v>: Sized {
443443
}
444444
}
445445

446-
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) {
447-
visitor.visit_id(mod_hir_id);
448-
for &item_id in module.item_ids {
449-
visitor.visit_nested_item(item_id);
450-
}
451-
}
452-
453-
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
454-
walk_list!(visitor, visit_param, body.params);
455-
visitor.visit_expr(&body.value);
456-
}
457-
458-
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
459-
// Intentionally visiting the expr first - the initialization expr
460-
// dominates the local's definition.
461-
walk_list!(visitor, visit_expr, &local.init);
462-
visitor.visit_id(local.hir_id);
463-
visitor.visit_pat(&local.pat);
464-
if let Some(els) = local.els {
465-
visitor.visit_block(els);
466-
}
467-
walk_list!(visitor, visit_ty, &local.ty);
468-
}
469-
470-
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
471-
visitor.visit_name(ident.name);
472-
}
473-
474-
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
475-
visitor.visit_ident(label.ident);
476-
}
477-
478-
pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v GenericArg<'v>) {
479-
match generic_arg {
480-
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
481-
GenericArg::Type(ty) => visitor.visit_ty(ty),
482-
GenericArg::Const(ct) => visitor.visit_anon_const(&ct.value),
483-
GenericArg::Infer(inf) => visitor.visit_infer(inf),
484-
}
485-
}
486-
487-
pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
488-
visitor.visit_id(lifetime.hir_id);
489-
match lifetime.name {
490-
LifetimeName::Param(_, ParamName::Plain(ident)) => {
491-
visitor.visit_ident(ident);
492-
}
493-
LifetimeName::Param(_, ParamName::Fresh)
494-
| LifetimeName::Param(_, ParamName::Error)
495-
| LifetimeName::Static
496-
| LifetimeName::Error
497-
| LifetimeName::ImplicitObjectLifetimeDefault
498-
| LifetimeName::Infer => {}
499-
}
500-
}
501-
502-
pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v PolyTraitRef<'v>) {
503-
walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
504-
visitor.visit_trait_ref(&trait_ref.trait_ref);
505-
}
506-
507-
pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) {
508-
visitor.visit_id(trait_ref.hir_ref_id);
509-
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
510-
}
511-
512446
pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param<'v>) {
513447
visitor.visit_id(param.hir_id);
514448
visitor.visit_pat(&param.pat);
@@ -605,142 +539,80 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
605539
}
606540
}
607541

608-
pub fn walk_inline_asm<'v, V: Visitor<'v>>(visitor: &mut V, asm: &'v InlineAsm<'v>, id: HirId) {
609-
for (op, op_sp) in asm.operands {
610-
match op {
611-
InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
612-
visitor.visit_expr(expr)
613-
}
614-
InlineAsmOperand::Out { expr, .. } => {
615-
if let Some(expr) = expr {
616-
visitor.visit_expr(expr);
617-
}
618-
}
619-
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
620-
visitor.visit_expr(in_expr);
621-
if let Some(out_expr) = out_expr {
622-
visitor.visit_expr(out_expr);
623-
}
624-
}
625-
InlineAsmOperand::Const { anon_const, .. }
626-
| InlineAsmOperand::SymFn { anon_const, .. } => visitor.visit_anon_const(anon_const),
627-
InlineAsmOperand::SymStatic { path, .. } => visitor.visit_qpath(path, id, *op_sp),
628-
}
629-
}
630-
}
631-
632-
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>, hir_id: HirId) {
633-
visitor.visit_id(hir_id);
634-
visitor.visit_path(path, hir_id);
542+
pub fn walk_body<'v, V: Visitor<'v>>(visitor: &mut V, body: &'v Body<'v>) {
543+
walk_list!(visitor, visit_param, body.params);
544+
visitor.visit_expr(&body.value);
635545
}
636546

637-
pub fn walk_enum_def<'v, V: Visitor<'v>>(
638-
visitor: &mut V,
639-
enum_definition: &'v EnumDef<'v>,
640-
item_id: HirId,
641-
) {
642-
visitor.visit_id(item_id);
643-
walk_list!(visitor, visit_variant, enum_definition.variants);
547+
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
548+
visitor.visit_name(ident.name);
644549
}
645550

646-
pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) {
647-
visitor.visit_ident(variant.ident);
648-
visitor.visit_id(variant.id);
649-
visitor.visit_variant_data(&variant.data);
650-
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
551+
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>, mod_hir_id: HirId) {
552+
visitor.visit_id(mod_hir_id);
553+
for &item_id in module.item_ids {
554+
visitor.visit_nested_item(item_id);
555+
}
651556
}
652557

653-
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
654-
visitor.visit_id(typ.hir_id);
558+
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
559+
visitor.visit_id(foreign_item.hir_id());
560+
visitor.visit_ident(foreign_item.ident);
655561

656-
match typ.kind {
657-
TyKind::Slice(ref ty) => visitor.visit_ty(ty),
658-
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
659-
TyKind::Rptr(ref lifetime, ref mutable_type) => {
660-
visitor.visit_lifetime(lifetime);
661-
visitor.visit_ty(&mutable_type.ty)
662-
}
663-
TyKind::Never => {}
664-
TyKind::Tup(tuple_element_types) => {
665-
walk_list!(visitor, visit_ty, tuple_element_types);
666-
}
667-
TyKind::BareFn(ref function_declaration) => {
668-
walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
669-
visitor.visit_fn_decl(&function_declaration.decl);
670-
}
671-
TyKind::Path(ref qpath) => {
672-
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
673-
}
674-
TyKind::OpaqueDef(item_id, lifetimes, _in_trait) => {
675-
visitor.visit_nested_item(item_id);
676-
walk_list!(visitor, visit_generic_arg, lifetimes);
677-
}
678-
TyKind::Array(ref ty, ref length) => {
679-
visitor.visit_ty(ty);
680-
visitor.visit_array_length(length)
681-
}
682-
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
683-
for bound in bounds {
684-
visitor.visit_poly_trait_ref(bound);
562+
match foreign_item.kind {
563+
ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => {
564+
visitor.visit_generics(generics);
565+
visitor.visit_fn_decl(function_declaration);
566+
for &param_name in param_names {
567+
visitor.visit_ident(param_name);
685568
}
686-
visitor.visit_lifetime(lifetime);
687569
}
688-
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
689-
TyKind::Infer | TyKind::Err => {}
570+
ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ),
571+
ForeignItemKind::Type => (),
690572
}
691573
}
692574

693-
pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
694-
visitor.visit_id(inf.hir_id);
695-
}
696-
697-
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) {
698-
match *qpath {
699-
QPath::Resolved(ref maybe_qself, ref path) => {
700-
walk_list!(visitor, visit_ty, maybe_qself);
701-
visitor.visit_path(path, id)
702-
}
703-
QPath::TypeRelative(ref qself, ref segment) => {
704-
visitor.visit_ty(qself);
705-
visitor.visit_path_segment(segment);
706-
}
707-
QPath::LangItem(..) => {}
575+
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
576+
// Intentionally visiting the expr first - the initialization expr
577+
// dominates the local's definition.
578+
walk_list!(visitor, visit_expr, &local.init);
579+
visitor.visit_id(local.hir_id);
580+
visitor.visit_pat(&local.pat);
581+
if let Some(els) = local.els {
582+
visitor.visit_block(els);
708583
}
584+
walk_list!(visitor, visit_ty, &local.ty);
709585
}
710586

711-
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
712-
for segment in path.segments {
713-
visitor.visit_path_segment(segment);
714-
}
587+
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
588+
visitor.visit_id(block.hir_id);
589+
walk_list!(visitor, visit_stmt, block.stmts);
590+
walk_list!(visitor, visit_expr, &block.expr);
715591
}
716592

717-
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) {
718-
visitor.visit_ident(segment.ident);
719-
visitor.visit_id(segment.hir_id);
720-
if let Some(ref args) = segment.args {
721-
visitor.visit_generic_args(args);
593+
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
594+
visitor.visit_id(statement.hir_id);
595+
match statement.kind {
596+
StmtKind::Local(ref local) => visitor.visit_local(local),
597+
StmtKind::Item(item) => visitor.visit_nested_item(item),
598+
StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
599+
visitor.visit_expr(expression)
600+
}
722601
}
723602
}
724603

725-
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) {
726-
walk_list!(visitor, visit_generic_arg, generic_args.args);
727-
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
728-
}
729-
730-
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
731-
visitor: &mut V,
732-
type_binding: &'v TypeBinding<'v>,
733-
) {
734-
visitor.visit_id(type_binding.hir_id);
735-
visitor.visit_ident(type_binding.ident);
736-
visitor.visit_generic_args(type_binding.gen_args);
737-
match type_binding.kind {
738-
TypeBindingKind::Equality { ref term } => match term {
739-
Term::Ty(ref ty) => visitor.visit_ty(ty),
740-
Term::Const(ref c) => visitor.visit_anon_const(c),
741-
},
742-
TypeBindingKind::Constraint { bounds } => walk_list!(visitor, visit_param_bound, bounds),
604+
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
605+
visitor.visit_id(arm.hir_id);
606+
visitor.visit_pat(&arm.pat);
607+
if let Some(ref g) = arm.guard {
608+
match g {
609+
Guard::If(ref e) => visitor.visit_expr(e),
610+
Guard::IfLet(ref l) => {
611+
visitor.visit_let_expr(l);
612+
}
613+
}
743614
}
615+
visitor.visit_expr(&arm.body);
744616
}
745617

746618
pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat<'v>) {
@@ -788,33 +660,181 @@ pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'
788660
visitor.visit_pat(&field.pat)
789661
}
790662

791-
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
792-
visitor.visit_id(foreign_item.hir_id());
793-
visitor.visit_ident(foreign_item.ident);
794-
795-
match foreign_item.kind {
796-
ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => {
797-
visitor.visit_generics(generics);
798-
visitor.visit_fn_decl(function_declaration);
799-
for &param_name in param_names {
800-
visitor.visit_ident(param_name);
801-
}
802-
}
803-
ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ),
804-
ForeignItemKind::Type => (),
663+
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
664+
match len {
665+
&ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
666+
ArrayLen::Body(c) => visitor.visit_anon_const(c),
805667
}
806668
}
807669

808-
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
809-
match *bound {
810-
GenericBound::Trait(ref typ, _modifier) => {
811-
visitor.visit_poly_trait_ref(typ);
670+
pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
671+
visitor.visit_id(constant.hir_id);
672+
visitor.visit_nested_body(constant.body);
673+
}
674+
675+
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
676+
visitor.visit_id(expression.hir_id);
677+
match expression.kind {
678+
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
679+
ExprKind::Array(subexpressions) => {
680+
walk_list!(visitor, visit_expr, subexpressions);
812681
}
813-
GenericBound::LangItemTrait(_, _span, hir_id, args) => {
814-
visitor.visit_id(hir_id);
815-
visitor.visit_generic_args(args);
682+
ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const),
683+
ExprKind::Repeat(ref element, ref count) => {
684+
visitor.visit_expr(element);
685+
visitor.visit_array_length(count)
816686
}
817-
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
687+
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
688+
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
689+
walk_list!(visitor, visit_expr_field, fields);
690+
walk_list!(visitor, visit_expr, optional_base);
691+
}
692+
ExprKind::Tup(subexpressions) => {
693+
walk_list!(visitor, visit_expr, subexpressions);
694+
}
695+
ExprKind::Call(ref callee_expression, arguments) => {
696+
visitor.visit_expr(callee_expression);
697+
walk_list!(visitor, visit_expr, arguments);
698+
}
699+
ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
700+
visitor.visit_path_segment(segment);
701+
visitor.visit_expr(receiver);
702+
walk_list!(visitor, visit_expr, arguments);
703+
}
704+
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
705+
visitor.visit_expr(left_expression);
706+
visitor.visit_expr(right_expression)
707+
}
708+
ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
709+
visitor.visit_expr(subexpression)
710+
}
711+
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
712+
visitor.visit_expr(subexpression);
713+
visitor.visit_ty(typ)
714+
}
715+
ExprKind::DropTemps(ref subexpression) => {
716+
visitor.visit_expr(subexpression);
717+
}
718+
ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
719+
ExprKind::If(ref cond, ref then, ref else_opt) => {
720+
visitor.visit_expr(cond);
721+
visitor.visit_expr(then);
722+
walk_list!(visitor, visit_expr, else_opt);
723+
}
724+
ExprKind::Loop(ref block, ref opt_label, _, _) => {
725+
walk_list!(visitor, visit_label, opt_label);
726+
visitor.visit_block(block);
727+
}
728+
ExprKind::Match(ref subexpression, arms, _) => {
729+
visitor.visit_expr(subexpression);
730+
walk_list!(visitor, visit_arm, arms);
731+
}
732+
ExprKind::Closure(&Closure {
733+
binder: _,
734+
bound_generic_params,
735+
fn_decl,
736+
body,
737+
capture_clause: _,
738+
fn_decl_span: _,
739+
movability: _,
740+
}) => {
741+
walk_list!(visitor, visit_generic_param, bound_generic_params);
742+
visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, expression.hir_id)
743+
}
744+
ExprKind::Block(ref block, ref opt_label) => {
745+
walk_list!(visitor, visit_label, opt_label);
746+
visitor.visit_block(block);
747+
}
748+
ExprKind::Assign(ref lhs, ref rhs, _) => {
749+
visitor.visit_expr(rhs);
750+
visitor.visit_expr(lhs)
751+
}
752+
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
753+
visitor.visit_expr(right_expression);
754+
visitor.visit_expr(left_expression);
755+
}
756+
ExprKind::Field(ref subexpression, ident) => {
757+
visitor.visit_expr(subexpression);
758+
visitor.visit_ident(ident);
759+
}
760+
ExprKind::Index(ref main_expression, ref index_expression) => {
761+
visitor.visit_expr(main_expression);
762+
visitor.visit_expr(index_expression)
763+
}
764+
ExprKind::Path(ref qpath) => {
765+
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
766+
}
767+
ExprKind::Break(ref destination, ref opt_expr) => {
768+
walk_list!(visitor, visit_label, &destination.label);
769+
walk_list!(visitor, visit_expr, opt_expr);
770+
}
771+
ExprKind::Continue(ref destination) => {
772+
walk_list!(visitor, visit_label, &destination.label);
773+
}
774+
ExprKind::Ret(ref optional_expression) => {
775+
walk_list!(visitor, visit_expr, optional_expression);
776+
}
777+
ExprKind::InlineAsm(ref asm) => {
778+
visitor.visit_inline_asm(asm, expression.hir_id);
779+
}
780+
ExprKind::Yield(ref subexpression, _) => {
781+
visitor.visit_expr(subexpression);
782+
}
783+
ExprKind::Lit(_) | ExprKind::Err => {}
784+
}
785+
}
786+
787+
pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
788+
// match the visit order in walk_local
789+
visitor.visit_expr(let_expr.init);
790+
visitor.visit_id(let_expr.hir_id);
791+
visitor.visit_pat(let_expr.pat);
792+
walk_list!(visitor, visit_ty, let_expr.ty);
793+
}
794+
795+
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
796+
visitor.visit_id(field.hir_id);
797+
visitor.visit_ident(field.ident);
798+
visitor.visit_expr(&field.expr)
799+
}
800+
801+
pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
802+
visitor.visit_id(typ.hir_id);
803+
804+
match typ.kind {
805+
TyKind::Slice(ref ty) => visitor.visit_ty(ty),
806+
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty),
807+
TyKind::Rptr(ref lifetime, ref mutable_type) => {
808+
visitor.visit_lifetime(lifetime);
809+
visitor.visit_ty(&mutable_type.ty)
810+
}
811+
TyKind::Never => {}
812+
TyKind::Tup(tuple_element_types) => {
813+
walk_list!(visitor, visit_ty, tuple_element_types);
814+
}
815+
TyKind::BareFn(ref function_declaration) => {
816+
walk_list!(visitor, visit_generic_param, function_declaration.generic_params);
817+
visitor.visit_fn_decl(&function_declaration.decl);
818+
}
819+
TyKind::Path(ref qpath) => {
820+
visitor.visit_qpath(qpath, typ.hir_id, typ.span);
821+
}
822+
TyKind::OpaqueDef(item_id, lifetimes, _in_trait) => {
823+
visitor.visit_nested_item(item_id);
824+
walk_list!(visitor, visit_generic_arg, lifetimes);
825+
}
826+
TyKind::Array(ref ty, ref length) => {
827+
visitor.visit_ty(ty);
828+
visitor.visit_array_length(length)
829+
}
830+
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
831+
for bound in bounds {
832+
visitor.visit_poly_trait_ref(bound);
833+
}
834+
visitor.visit_lifetime(lifetime);
835+
}
836+
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
837+
TyKind::Infer | TyKind::Err => {}
818838
}
819839
}
820840

@@ -879,25 +899,16 @@ pub fn walk_where_predicate<'v, V: Visitor<'v>>(
879899
}
880900
}
881901

882-
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) {
883-
if let FnRetTy::Return(ref output_ty) = *ret_ty {
884-
visitor.visit_ty(output_ty)
885-
}
886-
}
887-
888902
pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl<'v>) {
889903
for ty in function_declaration.inputs {
890904
visitor.visit_ty(ty)
891905
}
892906
walk_fn_ret_ty(visitor, &function_declaration.output)
893907
}
894908

895-
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) {
896-
match function_kind {
897-
FnKind::ItemFn(_, generics, ..) => {
898-
visitor.visit_generics(generics);
899-
}
900-
FnKind::Closure | FnKind::Method(..) => {}
909+
pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FnRetTy<'v>) {
910+
if let FnRetTy::Return(ref output_ty) = *ret_ty {
911+
visitor.visit_ty(output_ty)
901912
}
902913
}
903914

@@ -914,6 +925,20 @@ pub fn walk_fn<'v, V: Visitor<'v>>(
914925
visitor.visit_nested_body(body_id)
915926
}
916927

928+
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<'v>) {
929+
match function_kind {
930+
FnKind::ItemFn(_, generics, ..) => {
931+
visitor.visit_generics(generics);
932+
}
933+
FnKind::Closure | FnKind::Method(..) => {}
934+
}
935+
}
936+
937+
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>, hir_id: HirId) {
938+
visitor.visit_id(hir_id);
939+
visitor.visit_path(path, hir_id);
940+
}
941+
917942
pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem<'v>) {
918943
// N.B., deliberately force a compilation error if/when new fields are added.
919944
let TraitItem { ident, generics, ref defaultness, ref kind, span, owner_id: _ } = *trait_item;
@@ -1008,6 +1033,29 @@ pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'
10081033
visitor.visit_associated_item_kind(kind);
10091034
}
10101035

1036+
pub fn walk_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v TraitRef<'v>) {
1037+
visitor.visit_id(trait_ref.hir_ref_id);
1038+
visitor.visit_path(&trait_ref.path, trait_ref.hir_ref_id)
1039+
}
1040+
1041+
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
1042+
match *bound {
1043+
GenericBound::Trait(ref typ, _modifier) => {
1044+
visitor.visit_poly_trait_ref(typ);
1045+
}
1046+
GenericBound::LangItemTrait(_, _span, hir_id, args) => {
1047+
visitor.visit_id(hir_id);
1048+
visitor.visit_generic_args(args);
1049+
}
1050+
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
1051+
}
1052+
}
1053+
1054+
pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v PolyTraitRef<'v>) {
1055+
walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
1056+
visitor.visit_trait_ref(&trait_ref.trait_ref);
1057+
}
1058+
10111059
pub fn walk_struct_def<'v, V: Visitor<'v>>(
10121060
visitor: &mut V,
10131061
struct_definition: &'v VariantData<'v>,
@@ -1022,173 +1070,101 @@ pub fn walk_field_def<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v FieldDef<'
10221070
visitor.visit_ty(&field.ty);
10231071
}
10241072

1025-
pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block<'v>) {
1026-
visitor.visit_id(block.hir_id);
1027-
walk_list!(visitor, visit_stmt, block.stmts);
1028-
walk_list!(visitor, visit_expr, &block.expr);
1073+
pub fn walk_enum_def<'v, V: Visitor<'v>>(
1074+
visitor: &mut V,
1075+
enum_definition: &'v EnumDef<'v>,
1076+
item_id: HirId,
1077+
) {
1078+
visitor.visit_id(item_id);
1079+
walk_list!(visitor, visit_variant, enum_definition.variants);
10291080
}
10301081

1031-
pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
1032-
visitor.visit_id(statement.hir_id);
1033-
match statement.kind {
1034-
StmtKind::Local(ref local) => visitor.visit_local(local),
1035-
StmtKind::Item(item) => visitor.visit_nested_item(item),
1036-
StmtKind::Expr(ref expression) | StmtKind::Semi(ref expression) => {
1037-
visitor.visit_expr(expression)
1038-
}
1039-
}
1082+
pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, variant: &'v Variant<'v>) {
1083+
visitor.visit_ident(variant.ident);
1084+
visitor.visit_id(variant.id);
1085+
visitor.visit_variant_data(&variant.data);
1086+
walk_list!(visitor, visit_anon_const, &variant.disr_expr);
10401087
}
10411088

1042-
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
1043-
match len {
1044-
&ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
1045-
ArrayLen::Body(c) => visitor.visit_anon_const(c),
1046-
}
1089+
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
1090+
visitor.visit_ident(label.ident);
10471091
}
10481092

1049-
pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
1050-
visitor.visit_id(constant.hir_id);
1051-
visitor.visit_nested_body(constant.body);
1093+
pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
1094+
visitor.visit_id(inf.hir_id);
10521095
}
10531096

1054-
pub fn walk_let_expr<'v, V: Visitor<'v>>(visitor: &mut V, let_expr: &'v Let<'v>) {
1055-
// match the visit order in walk_local
1056-
visitor.visit_expr(let_expr.init);
1057-
visitor.visit_id(let_expr.hir_id);
1058-
visitor.visit_pat(let_expr.pat);
1059-
walk_list!(visitor, visit_ty, let_expr.ty);
1097+
pub fn walk_generic_arg<'v, V: Visitor<'v>>(visitor: &mut V, generic_arg: &'v GenericArg<'v>) {
1098+
match generic_arg {
1099+
GenericArg::Lifetime(lt) => visitor.visit_lifetime(lt),
1100+
GenericArg::Type(ty) => visitor.visit_ty(ty),
1101+
GenericArg::Const(ct) => visitor.visit_anon_const(&ct.value),
1102+
GenericArg::Infer(inf) => visitor.visit_infer(inf),
1103+
}
10601104
}
10611105

1062-
pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField<'v>) {
1063-
visitor.visit_id(field.hir_id);
1064-
visitor.visit_ident(field.ident);
1065-
visitor.visit_expr(&field.expr)
1106+
pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) {
1107+
visitor.visit_id(lifetime.hir_id);
1108+
match lifetime.name {
1109+
LifetimeName::Param(_, ParamName::Plain(ident)) => {
1110+
visitor.visit_ident(ident);
1111+
}
1112+
LifetimeName::Param(_, ParamName::Fresh)
1113+
| LifetimeName::Param(_, ParamName::Error)
1114+
| LifetimeName::Static
1115+
| LifetimeName::Error
1116+
| LifetimeName::ImplicitObjectLifetimeDefault
1117+
| LifetimeName::Infer => {}
1118+
}
10661119
}
10671120

1068-
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
1069-
visitor.visit_id(expression.hir_id);
1070-
match expression.kind {
1071-
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
1072-
ExprKind::Array(subexpressions) => {
1073-
walk_list!(visitor, visit_expr, subexpressions);
1074-
}
1075-
ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const),
1076-
ExprKind::Repeat(ref element, ref count) => {
1077-
visitor.visit_expr(element);
1078-
visitor.visit_array_length(count)
1079-
}
1080-
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
1081-
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1082-
walk_list!(visitor, visit_expr_field, fields);
1083-
walk_list!(visitor, visit_expr, optional_base);
1084-
}
1085-
ExprKind::Tup(subexpressions) => {
1086-
walk_list!(visitor, visit_expr, subexpressions);
1087-
}
1088-
ExprKind::Call(ref callee_expression, arguments) => {
1089-
visitor.visit_expr(callee_expression);
1090-
walk_list!(visitor, visit_expr, arguments);
1121+
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) {
1122+
match *qpath {
1123+
QPath::Resolved(ref maybe_qself, ref path) => {
1124+
walk_list!(visitor, visit_ty, maybe_qself);
1125+
visitor.visit_path(path, id)
10911126
}
1092-
ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
1127+
QPath::TypeRelative(ref qself, ref segment) => {
1128+
visitor.visit_ty(qself);
10931129
visitor.visit_path_segment(segment);
1094-
visitor.visit_expr(receiver);
1095-
walk_list!(visitor, visit_expr, arguments);
10961130
}
1097-
ExprKind::Binary(_, ref left_expression, ref right_expression) => {
1098-
visitor.visit_expr(left_expression);
1099-
visitor.visit_expr(right_expression)
1100-
}
1101-
ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => {
1102-
visitor.visit_expr(subexpression)
1103-
}
1104-
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => {
1105-
visitor.visit_expr(subexpression);
1106-
visitor.visit_ty(typ)
1107-
}
1108-
ExprKind::DropTemps(ref subexpression) => {
1109-
visitor.visit_expr(subexpression);
1110-
}
1111-
ExprKind::Let(ref let_expr) => visitor.visit_let_expr(let_expr),
1112-
ExprKind::If(ref cond, ref then, ref else_opt) => {
1113-
visitor.visit_expr(cond);
1114-
visitor.visit_expr(then);
1115-
walk_list!(visitor, visit_expr, else_opt);
1116-
}
1117-
ExprKind::Loop(ref block, ref opt_label, _, _) => {
1118-
walk_list!(visitor, visit_label, opt_label);
1119-
visitor.visit_block(block);
1120-
}
1121-
ExprKind::Match(ref subexpression, arms, _) => {
1122-
visitor.visit_expr(subexpression);
1123-
walk_list!(visitor, visit_arm, arms);
1124-
}
1125-
ExprKind::Closure(&Closure {
1126-
binder: _,
1127-
bound_generic_params,
1128-
fn_decl,
1129-
body,
1130-
capture_clause: _,
1131-
fn_decl_span: _,
1132-
movability: _,
1133-
}) => {
1134-
walk_list!(visitor, visit_generic_param, bound_generic_params);
1135-
visitor.visit_fn(FnKind::Closure, fn_decl, body, expression.span, expression.hir_id)
1136-
}
1137-
ExprKind::Block(ref block, ref opt_label) => {
1138-
walk_list!(visitor, visit_label, opt_label);
1139-
visitor.visit_block(block);
1140-
}
1141-
ExprKind::Assign(ref lhs, ref rhs, _) => {
1142-
visitor.visit_expr(rhs);
1143-
visitor.visit_expr(lhs)
1144-
}
1145-
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => {
1146-
visitor.visit_expr(right_expression);
1147-
visitor.visit_expr(left_expression);
1148-
}
1149-
ExprKind::Field(ref subexpression, ident) => {
1150-
visitor.visit_expr(subexpression);
1151-
visitor.visit_ident(ident);
1152-
}
1153-
ExprKind::Index(ref main_expression, ref index_expression) => {
1154-
visitor.visit_expr(main_expression);
1155-
visitor.visit_expr(index_expression)
1156-
}
1157-
ExprKind::Path(ref qpath) => {
1158-
visitor.visit_qpath(qpath, expression.hir_id, expression.span);
1159-
}
1160-
ExprKind::Break(ref destination, ref opt_expr) => {
1161-
walk_list!(visitor, visit_label, &destination.label);
1162-
walk_list!(visitor, visit_expr, opt_expr);
1163-
}
1164-
ExprKind::Continue(ref destination) => {
1165-
walk_list!(visitor, visit_label, &destination.label);
1166-
}
1167-
ExprKind::Ret(ref optional_expression) => {
1168-
walk_list!(visitor, visit_expr, optional_expression);
1169-
}
1170-
ExprKind::InlineAsm(ref asm) => {
1171-
visitor.visit_inline_asm(asm, expression.hir_id);
1172-
}
1173-
ExprKind::Yield(ref subexpression, _) => {
1174-
visitor.visit_expr(subexpression);
1175-
}
1176-
ExprKind::Lit(_) | ExprKind::Err => {}
1131+
QPath::LangItem(..) => {}
11771132
}
11781133
}
11791134

1180-
pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm<'v>) {
1181-
visitor.visit_id(arm.hir_id);
1182-
visitor.visit_pat(&arm.pat);
1183-
if let Some(ref g) = arm.guard {
1184-
match g {
1185-
Guard::If(ref e) => visitor.visit_expr(e),
1186-
Guard::IfLet(ref l) => {
1187-
visitor.visit_let_expr(l);
1188-
}
1189-
}
1135+
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
1136+
for segment in path.segments {
1137+
visitor.visit_path_segment(segment);
1138+
}
1139+
}
1140+
1141+
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) {
1142+
visitor.visit_ident(segment.ident);
1143+
visitor.visit_id(segment.hir_id);
1144+
if let Some(ref args) = segment.args {
1145+
visitor.visit_generic_args(args);
1146+
}
1147+
}
1148+
1149+
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) {
1150+
walk_list!(visitor, visit_generic_arg, generic_args.args);
1151+
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
1152+
}
1153+
1154+
pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
1155+
visitor: &mut V,
1156+
type_binding: &'v TypeBinding<'v>,
1157+
) {
1158+
visitor.visit_id(type_binding.hir_id);
1159+
visitor.visit_ident(type_binding.ident);
1160+
visitor.visit_generic_args(type_binding.gen_args);
1161+
match type_binding.kind {
1162+
TypeBindingKind::Equality { ref term } => match term {
1163+
Term::Ty(ref ty) => visitor.visit_ty(ty),
1164+
Term::Const(ref c) => visitor.visit_anon_const(c),
1165+
},
1166+
TypeBindingKind::Constraint { bounds } => walk_list!(visitor, visit_param_bound, bounds),
11901167
}
1191-
visitor.visit_expr(&arm.body);
11921168
}
11931169

11941170
pub fn walk_associated_item_kind<'v, V: Visitor<'v>>(_: &mut V, _: &'v AssocItemKind) {
@@ -1202,3 +1178,27 @@ pub fn walk_defaultness<'v, V: Visitor<'v>>(_: &mut V, _: &'v Defaultness) {
12021178
// the right thing to do, should content be added in the future,
12031179
// would be to walk it.
12041180
}
1181+
1182+
pub fn walk_inline_asm<'v, V: Visitor<'v>>(visitor: &mut V, asm: &'v InlineAsm<'v>, id: HirId) {
1183+
for (op, op_sp) in asm.operands {
1184+
match op {
1185+
InlineAsmOperand::In { expr, .. } | InlineAsmOperand::InOut { expr, .. } => {
1186+
visitor.visit_expr(expr)
1187+
}
1188+
InlineAsmOperand::Out { expr, .. } => {
1189+
if let Some(expr) = expr {
1190+
visitor.visit_expr(expr);
1191+
}
1192+
}
1193+
InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => {
1194+
visitor.visit_expr(in_expr);
1195+
if let Some(out_expr) = out_expr {
1196+
visitor.visit_expr(out_expr);
1197+
}
1198+
}
1199+
InlineAsmOperand::Const { anon_const, .. }
1200+
| InlineAsmOperand::SymFn { anon_const, .. } => visitor.visit_anon_const(anon_const),
1201+
InlineAsmOperand::SymStatic { path, .. } => visitor.visit_qpath(path, id, *op_sp),
1202+
}
1203+
}
1204+
}

0 commit comments

Comments
 (0)
Please sign in to comment.