Skip to content

Commit b7fdc7b

Browse files
committed
ty: remove unnecessary Predicate::walk_tys and collect_regions.
1 parent 3410aed commit b7fdc7b

File tree

3 files changed

+22
-103
lines changed

3 files changed

+22
-103
lines changed

src/librustc_middle/ty/fold.rs

-14
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,6 @@ where
263263
// Region folder
264264

265265
impl<'tcx> TyCtxt<'tcx> {
266-
/// Collects the free and escaping regions in `value` into `region_set`. Returns
267-
/// whether any late-bound regions were skipped
268-
pub fn collect_regions<T>(self, value: &T, region_set: &mut FxHashSet<ty::Region<'tcx>>) -> bool
269-
where
270-
T: TypeFoldable<'tcx>,
271-
{
272-
let mut have_bound_regions = false;
273-
self.fold_regions(value, &mut have_bound_regions, |r, d| {
274-
region_set.insert(self.mk_region(r.shifted_out_to_binder(d)));
275-
r
276-
});
277-
have_bound_regions
278-
}
279-
280266
/// Folds the escaping and free regions in `value` using `f`, and
281267
/// sets `skipped_regions` to true if any late-bound region was found
282268
/// and skipped.

src/librustc_middle/ty/mod.rs

-70
Original file line numberDiff line numberDiff line change
@@ -1518,77 +1518,7 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
15181518
}
15191519
}
15201520

1521-
// A custom iterator used by `Predicate::walk_tys`.
1522-
enum WalkTysIter<'tcx, I, J, K>
1523-
where
1524-
I: Iterator<Item = Ty<'tcx>>,
1525-
J: Iterator<Item = Ty<'tcx>>,
1526-
K: Iterator<Item = Ty<'tcx>>,
1527-
{
1528-
None,
1529-
One(Ty<'tcx>),
1530-
Two(Ty<'tcx>, Ty<'tcx>),
1531-
Types(I),
1532-
InputTypes(J),
1533-
ProjectionTypes(K),
1534-
}
1535-
1536-
impl<'tcx, I, J, K> Iterator for WalkTysIter<'tcx, I, J, K>
1537-
where
1538-
I: Iterator<Item = Ty<'tcx>>,
1539-
J: Iterator<Item = Ty<'tcx>>,
1540-
K: Iterator<Item = Ty<'tcx>>,
1541-
{
1542-
type Item = Ty<'tcx>;
1543-
1544-
fn next(&mut self) -> Option<Ty<'tcx>> {
1545-
match *self {
1546-
WalkTysIter::None => None,
1547-
WalkTysIter::One(item) => {
1548-
*self = WalkTysIter::None;
1549-
Some(item)
1550-
}
1551-
WalkTysIter::Two(item1, item2) => {
1552-
*self = WalkTysIter::One(item2);
1553-
Some(item1)
1554-
}
1555-
WalkTysIter::Types(ref mut iter) => iter.next(),
1556-
WalkTysIter::InputTypes(ref mut iter) => iter.next(),
1557-
WalkTysIter::ProjectionTypes(ref mut iter) => iter.next(),
1558-
}
1559-
}
1560-
}
1561-
15621521
impl<'tcx> Predicate<'tcx> {
1563-
/// Iterates over the types in this predicate. Note that in all
1564-
/// cases this is skipping over a binder, so late-bound regions
1565-
/// with depth 0 are bound by the predicate.
1566-
pub fn walk_tys(&'a self) -> impl Iterator<Item = Ty<'tcx>> + 'a {
1567-
match *self {
1568-
ty::Predicate::Trait(ref data, _) => {
1569-
WalkTysIter::InputTypes(data.skip_binder().input_types())
1570-
}
1571-
ty::Predicate::Subtype(binder) => {
1572-
let SubtypePredicate { a, b, a_is_expected: _ } = binder.skip_binder();
1573-
WalkTysIter::Two(a, b)
1574-
}
1575-
ty::Predicate::TypeOutlives(binder) => WalkTysIter::One(binder.skip_binder().0),
1576-
ty::Predicate::RegionOutlives(..) => WalkTysIter::None,
1577-
ty::Predicate::Projection(ref data) => {
1578-
let inner = data.skip_binder();
1579-
WalkTysIter::ProjectionTypes(
1580-
inner.projection_ty.substs.types().chain(Some(inner.ty)),
1581-
)
1582-
}
1583-
ty::Predicate::WellFormed(data) => WalkTysIter::One(data),
1584-
ty::Predicate::ObjectSafe(_trait_def_id) => WalkTysIter::None,
1585-
ty::Predicate::ClosureKind(_closure_def_id, closure_substs, _kind) => {
1586-
WalkTysIter::Types(closure_substs.types())
1587-
}
1588-
ty::Predicate::ConstEvaluatable(_, substs) => WalkTysIter::Types(substs.types()),
1589-
}
1590-
}
1591-
15921522
pub fn to_opt_poly_trait_ref(&self) -> Option<PolyTraitRef<'tcx>> {
15931523
match *self {
15941524
Predicate::Trait(ref t, _) => Some(t.to_poly_trait_ref()),

src/librustdoc/clean/auto_trait.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,28 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
315315
tcx: TyCtxt<'tcx>,
316316
pred: ty::Predicate<'tcx>,
317317
) -> FxHashSet<GenericParamDef> {
318-
pred.walk_tys()
319-
.flat_map(|t| {
320-
let mut regions = FxHashSet::default();
321-
tcx.collect_regions(&t, &mut regions);
322-
323-
regions.into_iter().flat_map(|r| {
324-
match r {
325-
// We only care about late bound regions, as we need to add them
326-
// to the 'for<>' section
327-
&ty::ReLateBound(_, ty::BoundRegion::BrNamed(_, name)) => {
328-
Some(GenericParamDef {
329-
name: name.to_string(),
330-
kind: GenericParamDefKind::Lifetime,
331-
})
332-
}
333-
&ty::ReVar(_) | &ty::ReEarlyBound(_) | &ty::ReStatic => None,
334-
_ => panic!("Unexpected region type {:?}", r),
335-
}
336-
})
318+
let regions = match pred {
319+
ty::Predicate::Trait(poly_trait_pred, _) => {
320+
tcx.collect_referenced_late_bound_regions(&poly_trait_pred)
321+
}
322+
ty::Predicate::Projection(poly_proj_pred) => {
323+
tcx.collect_referenced_late_bound_regions(&poly_proj_pred)
324+
}
325+
_ => return FxHashSet::default(),
326+
};
327+
328+
regions
329+
.into_iter()
330+
.filter_map(|br| {
331+
match br {
332+
// We only care about named late bound regions, as we need to add them
333+
// to the 'for<>' section
334+
ty::BrNamed(_, name) => Some(GenericParamDef {
335+
name: name.to_string(),
336+
kind: GenericParamDefKind::Lifetime,
337+
}),
338+
_ => None,
339+
}
337340
})
338341
.collect()
339342
}

0 commit comments

Comments
 (0)