internally change regions to be covariant
This commit is contained in:
parent
c62665e09c
commit
381187dc76
18 changed files with 43 additions and 52 deletions
|
@ -221,8 +221,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
ty::Ref(region, ty, mutbl) => {
|
||||
let contra = self.contravariant(variance);
|
||||
self.add_constraints_from_region(current, region, contra);
|
||||
self.add_constraints_from_region(current, region, variance);
|
||||
self.add_constraints_from_mt(current, &ty::TypeAndMut { ty, mutbl }, variance);
|
||||
}
|
||||
|
||||
|
@ -254,9 +253,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
ty::Dynamic(data, r, _) => {
|
||||
// The type `Foo<T+'a>` is contravariant w/r/t `'a`:
|
||||
let contra = self.contravariant(variance);
|
||||
self.add_constraints_from_region(current, r, contra);
|
||||
// The type `Foo<T + 'a>` is covariant w/r/t `'a`:
|
||||
self.add_constraints_from_region(current, r, variance);
|
||||
|
||||
if let Some(poly_trait_ref) = data.principal() {
|
||||
self.add_constraints_from_invariant_substs(
|
||||
|
|
|
@ -79,7 +79,8 @@ impl<'tcx> TypeRelation<'tcx> for Glb<'_, '_, 'tcx> {
|
|||
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
|
||||
|
||||
let origin = Subtype(Box::new(self.fields.trace.clone()));
|
||||
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
|
||||
// GLB(&'static u8, &'a u8) == &RegionLUB('static, 'a) u8 == &'static u8
|
||||
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
|
||||
self.tcx(),
|
||||
origin,
|
||||
a,
|
||||
|
|
|
@ -79,7 +79,8 @@ impl<'tcx> TypeRelation<'tcx> for Lub<'_, '_, 'tcx> {
|
|||
debug!("{}.regions({:?}, {:?})", self.tag(), a, b);
|
||||
|
||||
let origin = Subtype(Box::new(self.fields.trace.clone()));
|
||||
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().lub_regions(
|
||||
// LUB(&'static u8, &'a u8) == &RegionGLB('static, 'a) u8 == &'a u8
|
||||
Ok(self.fields.infcx.inner.borrow_mut().unwrap_region_constraints().glb_regions(
|
||||
self.tcx(),
|
||||
origin,
|
||||
a,
|
||||
|
|
|
@ -663,13 +663,13 @@ where
|
|||
debug!(?v_b);
|
||||
|
||||
if self.ambient_covariance() {
|
||||
// Covariance: a <= b. Hence, `b: a`.
|
||||
self.push_outlives(v_b, v_a, self.ambient_variance_info);
|
||||
// Covariant: &'a u8 <: &'b u8. Hence, `'a: 'b`.
|
||||
self.push_outlives(v_a, v_b, self.ambient_variance_info);
|
||||
}
|
||||
|
||||
if self.ambient_contravariance() {
|
||||
// Contravariant: b <= a. Hence, `a: b`.
|
||||
self.push_outlives(v_a, v_b, self.ambient_variance_info);
|
||||
// Contravariant: &'b u8 <: &'a u8. Hence, `'b: 'a`.
|
||||
self.push_outlives(v_b, v_a, self.ambient_variance_info);
|
||||
}
|
||||
|
||||
Ok(a)
|
||||
|
|
|
@ -191,12 +191,13 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> {
|
|||
// from the "cause" field, we could perhaps give more tailored
|
||||
// error messages.
|
||||
let origin = SubregionOrigin::Subtype(Box::new(self.fields.trace.clone()));
|
||||
// Subtype(&'a u8, &'b u8) => Outlives('a: 'b) => SubRegion('b, 'a)
|
||||
self.fields
|
||||
.infcx
|
||||
.inner
|
||||
.borrow_mut()
|
||||
.unwrap_region_constraints()
|
||||
.make_subregion(origin, a, b);
|
||||
.make_subregion(origin, b, a);
|
||||
|
||||
Ok(a)
|
||||
}
|
||||
|
|
|
@ -443,12 +443,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||
if a_repr == b_repr =>
|
||||
{
|
||||
let region_bound = relation.with_cause(Cause::ExistentialRegionBound, |relation| {
|
||||
relation.relate_with_variance(
|
||||
ty::Contravariant,
|
||||
ty::VarianceDiagInfo::default(),
|
||||
a_region,
|
||||
b_region,
|
||||
)
|
||||
relation.relate(a_region, b_region)
|
||||
})?;
|
||||
Ok(tcx.mk_dynamic(relation.relate(a_obj, b_obj)?, region_bound, a_repr))
|
||||
}
|
||||
|
@ -487,12 +482,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>(
|
|||
}
|
||||
|
||||
(&ty::Ref(a_r, a_ty, a_mutbl), &ty::Ref(b_r, b_ty, b_mutbl)) => {
|
||||
let r = relation.relate_with_variance(
|
||||
ty::Contravariant,
|
||||
ty::VarianceDiagInfo::default(),
|
||||
a_r,
|
||||
b_r,
|
||||
)?;
|
||||
let r = relation.relate(a_r, b_r)?;
|
||||
let a_mt = ty::TypeAndMut { ty: a_ty, mutbl: a_mutbl };
|
||||
let b_mt = ty::TypeAndMut { ty: b_ty, mutbl: b_mutbl };
|
||||
let mt = relate_type_and_mut(relation, a_mt, b_mt, a)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue