Skip to content

Commit 615437b

Browse files
committed
Unify walk_where_predicate
1 parent 3468839 commit 615437b

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
@@ -582,6 +582,34 @@ macro_rules! make_ast_visitor {
582582
try_v!(visit_span!(vis, span));
583583
return_result!(V)
584584
}
585+
586+
pub fn walk_where_predicate<$($lt,)? V: $trait$(<$lt>)?>(
587+
vis: &mut V,
588+
predicate: ref_t!(WherePredicate)
589+
) -> result!(V) {
590+
match predicate {
591+
WherePredicate::BoundPredicate(bp) => {
592+
let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp;
593+
visit_list!(vis, visit_generic_param, flat_map_generic_param, bound_generic_params);
594+
try_v!(vis.visit_ty(bounded_ty));
595+
visit_list!(vis, visit_param_bound, bounds; BoundKind::Bound);
596+
try_v!(visit_span!(vis, span));
597+
}
598+
WherePredicate::RegionPredicate(rp) => {
599+
let WhereRegionPredicate { span, lifetime, bounds } = rp;
600+
try_v!(vis.visit_lifetime(lifetime, LifetimeCtxt::Bound));
601+
visit_list!(vis, visit_param_bound, bounds; BoundKind::Bound);
602+
try_v!(visit_span!(vis, span));
603+
}
604+
WherePredicate::EqPredicate(ep) => {
605+
let WhereEqPredicate { span, lhs_ty, rhs_ty } = ep;
606+
try_v!(vis.visit_ty(lhs_ty));
607+
try_v!(vis.visit_ty(rhs_ty));
608+
try_v!(visit_span!(vis, span));
609+
}
610+
}
611+
return_result!(V)
612+
}
585613
}
586614
}
587615

@@ -1126,33 +1154,6 @@ pub mod visit {
11261154
V::Result::output()
11271155
}
11281156

1129-
pub fn walk_where_predicate<'a, V: Visitor<'a>>(
1130-
visitor: &mut V,
1131-
predicate: &'a WherePredicate,
1132-
) -> V::Result {
1133-
match predicate {
1134-
WherePredicate::BoundPredicate(WhereBoundPredicate {
1135-
bounded_ty,
1136-
bounds,
1137-
bound_generic_params,
1138-
span: _,
1139-
}) => {
1140-
walk_list!(visitor, visit_generic_param, bound_generic_params);
1141-
try_visit!(visitor.visit_ty(bounded_ty));
1142-
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
1143-
}
1144-
WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, span: _ }) => {
1145-
try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound));
1146-
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
1147-
}
1148-
WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, span: _ }) => {
1149-
try_visit!(visitor.visit_ty(lhs_ty));
1150-
try_visit!(visitor.visit_ty(rhs_ty));
1151-
}
1152-
}
1153-
V::Result::output()
1154-
}
1155-
11561157
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Result {
11571158
match kind {
11581159
FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span: _ }, _vis, generics, body) => {
@@ -2175,30 +2176,6 @@ pub mod mut_visit {
21752176
vis.visit_span(span_after);
21762177
}
21772178

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

0 commit comments

Comments
 (0)