Skip to content

Commit db0e626

Browse files
committed
introduce a "comparison fn" instead of always use ==
1 parent 9b63dcc commit db0e626

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/librustc/infer/outlives/verify.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
153153
// like `<T as Foo<'a>>::Item`.
154154
let generic_ty = generic.to_ty(tcx);
155155
let c_b = self.param_env.caller_bounds;
156-
let mut param_bounds = self.collect_outlives_from_predicate_list(generic_ty, c_b);
156+
let mut param_bounds = self.collect_outlives_from_predicate_list(
157+
|ty| ty == generic_ty,
158+
c_b,
159+
);
157160

158161
// Next, collect regions we scraped from the well-formedness
159162
// constraints in the fn signature. To do that, we walk the list
@@ -241,7 +244,7 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
241244
let identity_substs = Substs::identity_for_item(tcx, assoc_item_def_id);
242245
let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs);
243246
self.collect_outlives_from_predicate_list(
244-
identity_proj,
247+
|ty| ty == identity_proj,
245248
traits::elaborate_predicates(tcx, trait_predicates.predicates),
246249
)
247250
}
@@ -252,20 +255,16 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
252255
/// when comparing `ty` for equality, so `ty` must be something
253256
/// that does not involve inference variables and where you
254257
/// otherwise want a precise match.
255-
fn collect_outlives_from_predicate_list<I, P>(
258+
fn collect_outlives_from_predicate_list(
256259
&self,
257-
ty: Ty<'tcx>,
258-
predicates: I,
259-
) -> Vec<ty::Region<'tcx>>
260-
where
261-
I: IntoIterator<Item = P>,
262-
P: AsRef<ty::Predicate<'tcx>>,
263-
{
260+
compare_ty: impl Fn(Ty<'tcx>) -> bool,
261+
predicates: impl IntoIterator<Item = impl AsRef<ty::Predicate<'tcx>>>,
262+
) -> Vec<ty::Region<'tcx>> {
264263
predicates
265264
.into_iter()
266265
.filter_map(|p| p.as_ref().to_opt_type_outlives())
267266
.filter_map(|p| p.no_late_bound_regions())
268-
.filter(|p| p.0 == ty)
267+
.filter(|p| compare_ty(p.0))
269268
.map(|p| p.1)
270269
.collect()
271270
}

0 commit comments

Comments
 (0)