1
Fork 0

Remove AliasRelationDirection::Supertype

This commit is contained in:
Michael Goulet 2023-03-22 16:58:51 +00:00
parent f6fd754680
commit 244cdaa457
5 changed files with 98 additions and 90 deletions

View file

@ -128,7 +128,7 @@ impl<'tcx> InferCtxt<'tcx> {
(_, ty::Alias(AliasKind::Projection, _)) | (ty::Alias(AliasKind::Projection, _), _)
if self.tcx.trait_solver_next() =>
{
relation.register_type_equate_obligation(a, b);
relation.register_type_relate_obligation(a, b);
Ok(a)
}
@ -848,10 +848,9 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
})]);
}
/// Register an obligation that both types must be equal to each other.
///
/// If they aren't equal then the relation doesn't hold.
fn register_type_equate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
/// Register an obligation that both types must be related to each other according to
/// the [`ty::AliasRelationDirection`] given by [`ObligationEmittingRelation::alias_relate_direction`]
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
@ -859,7 +858,8 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
))]);
}
/// Relation direction emitted for `AliasRelate` predicates
/// Relation direction emitted for `AliasRelate` predicates, corresponding to the direction
/// of the relation.
fn alias_relate_direction(&self) -> ty::AliasRelationDirection;
}

View file

@ -779,13 +779,31 @@ where
}
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
match self.ambient_variance {
ty::Variance::Covariant => ty::AliasRelationDirection::Subtype,
ty::Variance::Contravariant => ty::AliasRelationDirection::Supertype,
ty::Variance::Invariant => ty::AliasRelationDirection::Equate,
// FIXME(deferred_projection_equality): Implement this when we trigger it
unreachable!("manually overridden to handle ty::Variance::Contravariant ambient variance")
}
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
ty::Variance::Covariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Subtype,
),
// a :> b is b <: a
ty::Variance::Contravariant => ty::PredicateKind::AliasRelate(
b.into(),
a.into(),
ty::AliasRelationDirection::Subtype,
),
ty::Variance::Invariant => ty::PredicateKind::AliasRelate(
a.into(),
b.into(),
ty::AliasRelationDirection::Equate,
),
// FIXME(deferred_projection_equality): Implement this when we trigger it.
// Probably just need to do nothing here.
ty::Variance::Bivariant => unreachable!(),
}
})]);
}
}