1
Fork 0

Elaborate param_env predicates when checking if type outlives involving projection holds

This commit is contained in:
Jack Huey 2022-01-09 23:53:57 -05:00
parent e012a191d7
commit ad57295fc9
6 changed files with 90 additions and 6 deletions

View file

@ -164,7 +164,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
"cannot process registered region obligations in a snapshot"
);
debug!("process_registered_region_obligations()");
debug!(?param_env, "process_registered_region_obligations()");
let my_region_obligations = self.take_registered_region_obligations();
@ -356,6 +356,8 @@ where
let trait_bounds: Vec<_> =
self.verify_bound.projection_declared_bounds_from_trait(projection_ty).collect();
debug!(?trait_bounds);
// Compute the bounds we can derive from the environment. This
// is an "approximate" match -- in some cases, these bounds
// may not apply.

View file

@ -241,10 +241,19 @@ impl<'tcx> Elaborator<'tcx> {
Component::UnresolvedInferenceVariable(_) => None,
Component::Projection(_) | Component::EscapingProjection(_) => {
// We can probably do more here. This
// corresponds to a case like `<T as
// Foo<'a>>::U: 'b`.
Component::Projection(projection) => {
// We might end up here if we have `Foo<<Bar as Baz>::Assoc>: 'a`.
// With this, we can deduce that `<Bar as Baz>::Assoc: 'a`.
let ty =
tcx.mk_projection(projection.item_def_id, projection.substs);
Some(ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(
ty, r_min,
)))
}
Component::EscapingProjection(_) => {
// We might be able to do more here, but we don't
// want to deal with escaping vars right now.
None
}
})