Skip to content

Commit 4b193cb

Browse files
committed
propagate the compare_ty fn further up
1 parent 13d579b commit 4b193cb

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/librustc/infer/outlives/verify.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,15 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
102102
self.declared_projection_bounds_from_trait(projection_ty)
103103
}
104104

105-
pub fn projection_bound(
106-
&self,
107-
projection_ty: ty::ProjectionTy<'tcx>,
108-
) -> VerifyBound<'tcx> {
109-
debug!(
110-
"projection_bound(projection_ty={:?})",
111-
projection_ty
112-
);
105+
pub fn projection_bound(&self, projection_ty: ty::ProjectionTy<'tcx>) -> VerifyBound<'tcx> {
106+
debug!("projection_bound(projection_ty={:?})", projection_ty);
113107

114108
// Search the env for where clauses like `P: 'a`.
115109
let mut declared_bounds =
116110
self.declared_generic_bounds_from_env(GenericKind::Projection(projection_ty));
117111

118112
// Extend with bounds that we can find from the trait.
119-
declared_bounds.extend(
120-
self.projection_declared_bounds_from_trait(projection_ty)
121-
);
113+
declared_bounds.extend(self.projection_declared_bounds_from_trait(projection_ty));
122114

123115
debug!("projection_bound: declared_bounds = {:?}", declared_bounds);
124116

@@ -158,6 +150,14 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
158150
fn declared_generic_bounds_from_env(
159151
&self,
160152
generic: GenericKind<'tcx>,
153+
) -> Vec<ty::Region<'tcx>> {
154+
let generic_ty = generic.to_ty(self.tcx);
155+
self.declared_generic_bounds_from_env_with_compare_fn(|ty| ty == generic_ty)
156+
}
157+
158+
fn declared_generic_bounds_from_env_with_compare_fn(
159+
&self,
160+
compare_ty: impl Fn(Ty<'tcx>) -> bool,
161161
) -> Vec<ty::Region<'tcx>> {
162162
let tcx = self.tcx;
163163

@@ -167,12 +167,8 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
167167
// dubious for projections, but it will work for simple cases
168168
// like `T` and `T::Item`. It may not work as well for things
169169
// like `<T as Foo<'a>>::Item`.
170-
let generic_ty = generic.to_ty(tcx);
171170
let c_b = self.param_env.caller_bounds;
172-
let mut param_bounds = self.collect_outlives_from_predicate_list(
173-
|ty| ty == generic_ty,
174-
c_b,
175-
);
171+
let mut param_bounds = self.collect_outlives_from_predicate_list(&compare_ty, c_b);
176172

177173
// Next, collect regions we scraped from the well-formedness
178174
// constraints in the fn signature. To do that, we walk the list
@@ -186,8 +182,11 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
186182
// well-formed, then, A must be lower-generic by `'a`, but we
187183
// don't know that this holds from first principles.
188184
for &(r, p) in self.region_bound_pairs {
189-
debug!("generic={:?} p={:?}", generic, p);
190-
if generic == p {
185+
debug!(
186+
"declared_generic_bounds_from_env_with_compare_fn: region_bound_pair = {:?}",
187+
(r, p)
188+
);
189+
if compare_ty(p.to_ty(tcx)) {
191190
param_bounds.push(r);
192191
}
193192
}

0 commit comments

Comments
 (0)