Skip to content

Commit f90cad5

Browse files
committed
Unify walk_where_predicate
1 parent 71c7203 commit f90cad5

File tree

1 file changed

+28
-51
lines changed

1 file changed

+28
-51
lines changed

compiler/rustc_ast/src/visitors.rs

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,34 @@ macro_rules! make_ast_visitor {
577577
try_v!(visit_span!(vis, span));
578578
return_result!(V)
579579
}
580+
581+
pub fn walk_where_predicate<$($lt,)? V: $trait$(<$lt>)?>(
582+
vis: &mut V,
583+
predicate: ref_t!(WherePredicate)
584+
) -> result!(V) {
585+
match predicate {
586+
WherePredicate::BoundPredicate(bp) => {
587+
let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp;
588+
visit_list!(vis, visit_generic_param, flat_map_generic_param, bound_generic_params);
589+
try_v!(vis.visit_ty(bounded_ty));
590+
visit_list!(vis, visit_param_bound, bounds; BoundKind::Bound);
591+
try_v!(visit_span!(vis, span));
592+
}
593+
WherePredicate::RegionPredicate(rp) => {
594+
let WhereRegionPredicate { span, lifetime, bounds } = rp;
595+
try_v!(vis.visit_lifetime(lifetime, LifetimeCtxt::Bound));
596+
visit_list!(vis, visit_param_bound, bounds; BoundKind::Bound);
597+
try_v!(visit_span!(vis, span));
598+
}
599+
WherePredicate::EqPredicate(ep) => {
600+
let WhereEqPredicate { span, lhs_ty, rhs_ty } = ep;
601+
try_v!(vis.visit_ty(lhs_ty));
602+
try_v!(vis.visit_ty(rhs_ty));
603+
try_v!(visit_span!(vis, span));
604+
}
605+
}
606+
return_result!(V)
607+
}
580608
}
581609
}
582610

@@ -1121,33 +1149,6 @@ pub mod visit {
11211149
V::Result::output()
11221150
}
11231151

1124-
pub fn walk_where_predicate<'a, V: Visitor<'a>>(
1125-
visitor: &mut V,
1126-
predicate: &'a WherePredicate,
1127-
) -> V::Result {
1128-
match predicate {
1129-
WherePredicate::BoundPredicate(WhereBoundPredicate {
1130-
bounded_ty,
1131-
bounds,
1132-
bound_generic_params,
1133-
span: _,
1134-
}) => {
1135-
walk_list!(visitor, visit_generic_param, bound_generic_params);
1136-
try_visit!(visitor.visit_ty(bounded_ty));
1137-
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
1138-
}
1139-
WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, span: _ }) => {
1140-
try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound));
1141-
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
1142-
}
1143-
WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, span: _ }) => {
1144-
try_visit!(visitor.visit_ty(lhs_ty));
1145-
try_visit!(visitor.visit_ty(rhs_ty));
1146-
}
1147-
}
1148-
V::Result::output()
1149-
}
1150-
11511152
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
11521153
match kind {
11531154
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span: _ }, _vis, generics, body) => {
@@ -2170,30 +2171,6 @@ pub mod mut_visit {
21702171
vis.visit_span(span_after);
21712172
}
21722173

2173-
fn walk_where_predicate<T: MutVisitor>(vis: &mut T, pred: &mut WherePredicate) {
2174-
match pred {
2175-
WherePredicate::BoundPredicate(bp) => {
2176-
let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp;
2177-
bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
2178-
vis.visit_ty(bounded_ty);
2179-
visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound));
2180-
vis.visit_span(span);
2181-
}
2182-
WherePredicate::RegionPredicate(rp) => {
2183-
let WhereRegionPredicate { span, lifetime, bounds } = rp;
2184-
vis.visit_lifetime(lifetime, LifetimeCtxt::Bound);
2185-
visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound));
2186-
vis.visit_span(span);
2187-
}
2188-
WherePredicate::EqPredicate(ep) => {
2189-
let WhereEqPredicate { span, lhs_ty, rhs_ty } = ep;
2190-
vis.visit_ty(lhs_ty);
2191-
vis.visit_ty(rhs_ty);
2192-
vis.visit_span(span);
2193-
}
2194-
}
2195-
}
2196-
21972174
fn walk_variant_data<T: MutVisitor>(vis: &mut T, vdata: &mut VariantData) {
21982175
match vdata {
21992176
VariantData::Struct { fields, recovered: _ } => {

0 commit comments

Comments
 (0)