Skip to content

Commit 2e19482

Browse files
committed
Unify walk_where_predicate
1 parent 5acc907 commit 2e19482

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
@@ -1255,6 +1255,34 @@ macro_rules! make_ast_visitor {
12551255
return_result!(V)
12561256
}
12571257

1258+
pub fn walk_where_predicate<$($lt,)? V: $trait$(<$lt>)?>(
1259+
vis: &mut V,
1260+
predicate: ref_t!(WherePredicate)
1261+
) -> result!(V) {
1262+
match predicate {
1263+
WherePredicate::BoundPredicate(bp) => {
1264+
let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp;
1265+
visit_list!(vis, visit_generic_param, flat_map_generic_param, bound_generic_params);
1266+
try_v!(vis.visit_ty(bounded_ty));
1267+
visit_list!(vis, visit_param_bound, bounds; BoundKind::Bound);
1268+
try_v!(visit_span!(vis, span));
1269+
}
1270+
WherePredicate::RegionPredicate(rp) => {
1271+
let WhereRegionPredicate { span, lifetime, bounds } = rp;
1272+
try_v!(vis.visit_lifetime(lifetime, LifetimeCtxt::Bound));
1273+
visit_list!(vis, visit_param_bound, bounds; BoundKind::Bound);
1274+
try_v!(visit_span!(vis, span));
1275+
}
1276+
WherePredicate::EqPredicate(ep) => {
1277+
let WhereEqPredicate { span, lhs_ty, rhs_ty } = ep;
1278+
try_v!(vis.visit_ty(lhs_ty));
1279+
try_v!(vis.visit_ty(rhs_ty));
1280+
try_v!(visit_span!(vis, span));
1281+
}
1282+
}
1283+
return_result!(V)
1284+
}
1285+
12581286
derive_copy_clone!{
12591287
#[derive(Debug)]
12601288
pub enum FnKind<'a> {
@@ -1590,33 +1618,6 @@ pub mod visit {
15901618
V::Result::output()
15911619
}
15921620

1593-
pub fn walk_where_predicate<'a, V: Visitor<'a>>(
1594-
visitor: &mut V,
1595-
predicate: &'a WherePredicate,
1596-
) -> V::Result {
1597-
match predicate {
1598-
WherePredicate::BoundPredicate(WhereBoundPredicate {
1599-
bounded_ty,
1600-
bounds,
1601-
bound_generic_params,
1602-
span: _,
1603-
}) => {
1604-
walk_list!(visitor, visit_generic_param, bound_generic_params);
1605-
try_visit!(visitor.visit_ty(bounded_ty));
1606-
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
1607-
}
1608-
WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, span: _ }) => {
1609-
try_visit!(visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound));
1610-
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
1611-
}
1612-
WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, span: _ }) => {
1613-
try_visit!(visitor.visit_ty(lhs_ty));
1614-
try_visit!(visitor.visit_ty(rhs_ty));
1615-
}
1616-
}
1617-
V::Result::output()
1618-
}
1619-
16201621
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
16211622
visitor: &mut V,
16221623
item: &'a Item<AssocItemKind>,
@@ -2291,30 +2292,6 @@ pub mod mut_visit {
22912292
vis.visit_span(span_after);
22922293
}
22932294

2294-
fn walk_where_predicate<T: MutVisitor>(vis: &mut T, pred: &mut WherePredicate) {
2295-
match pred {
2296-
WherePredicate::BoundPredicate(bp) => {
2297-
let WhereBoundPredicate { span, bound_generic_params, bounded_ty, bounds } = bp;
2298-
bound_generic_params.flat_map_in_place(|param| vis.flat_map_generic_param(param));
2299-
vis.visit_ty(bounded_ty);
2300-
visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound));
2301-
vis.visit_span(span);
2302-
}
2303-
WherePredicate::RegionPredicate(rp) => {
2304-
let WhereRegionPredicate { span, lifetime, bounds } = rp;
2305-
vis.visit_lifetime(lifetime, LifetimeCtxt::Bound);
2306-
visit_vec(bounds, |bound| vis.visit_param_bound(bound, BoundKind::Bound));
2307-
vis.visit_span(span);
2308-
}
2309-
WherePredicate::EqPredicate(ep) => {
2310-
let WhereEqPredicate { span, lhs_ty, rhs_ty } = ep;
2311-
vis.visit_ty(lhs_ty);
2312-
vis.visit_ty(rhs_ty);
2313-
vis.visit_span(span);
2314-
}
2315-
}
2316-
}
2317-
23182295
fn visit_const_item<T: MutVisitor>(
23192296
ConstItem { defaultness, generics, ty, expr }: &mut ConstItem,
23202297
visitor: &mut T,

0 commit comments

Comments
 (0)