Skip to content

Commit f7b841a

Browse files
Combine sub and eq
1 parent a2999da commit f7b841a

File tree

10 files changed

+350
-462
lines changed

10 files changed

+350
-462
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,15 @@ impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
344344

345345
debug!(?self.ambient_variance);
346346
// In a bivariant context this always succeeds.
347-
let r =
348-
if self.ambient_variance == ty::Variance::Bivariant { a } else { self.relate(a, b)? };
347+
let r = if self.ambient_variance == ty::Variance::Bivariant {
348+
Ok(a)
349+
} else {
350+
self.relate(a, b)
351+
};
349352

350353
self.ambient_variance = old_ambient_variance;
351354

352-
Ok(r)
355+
r
353356
}
354357

355358
#[instrument(skip(self), level = "debug")]
@@ -572,10 +575,6 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx
572575
);
573576
}
574577

575-
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
576-
unreachable!("manually overridden to handle ty::Variance::Contravariant ambient variance")
577-
}
578-
579578
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
580579
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
581580
ty::Variance::Covariant => ty::PredicateKind::AliasRelate(

compiler/rustc_infer/src/infer/relate/combine.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
//! [TypeRelation::a_is_expected], so when dealing with contravariance
2323
//! this should be correctly updated.
2424
25-
use super::equate::Equate;
2625
use super::glb::Glb;
2726
use super::lub::Lub;
28-
use super::sub::Sub;
27+
use super::type_relating::TypeRelating;
2928
use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace};
3029
use crate::traits::{Obligation, PredicateObligations};
3130
use rustc_middle::infer::canonical::OriginalQueryValues;
@@ -303,12 +302,12 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
303302
self.infcx.tcx
304303
}
305304

306-
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> Equate<'a, 'infcx, 'tcx> {
307-
Equate::new(self, a_is_expected)
305+
pub fn equate<'a>(&'a mut self, a_is_expected: bool) -> TypeRelating<'a, 'infcx, 'tcx> {
306+
TypeRelating::new(self, a_is_expected, ty::Invariant)
308307
}
309308

310-
pub fn sub<'a>(&'a mut self, a_is_expected: bool) -> Sub<'a, 'infcx, 'tcx> {
311-
Sub::new(self, a_is_expected)
309+
pub fn sub<'a>(&'a mut self, a_is_expected: bool) -> TypeRelating<'a, 'infcx, 'tcx> {
310+
TypeRelating::new(self, a_is_expected, ty::Covariant)
312311
}
313312

314313
pub fn lub<'a>(&'a mut self, a_is_expected: bool) -> Lub<'a, 'infcx, 'tcx> {
@@ -345,17 +344,7 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
345344

346345
/// Register an obligation that both types must be related to each other according to
347346
/// the [`ty::AliasRelationDirection`] given by [`ObligationEmittingRelation::alias_relate_direction`]
348-
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
349-
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasRelate(
350-
a.into(),
351-
b.into(),
352-
self.alias_relate_direction(),
353-
))]);
354-
}
355-
356-
/// Relation direction emitted for `AliasRelate` predicates, corresponding to the direction
357-
/// of the relation.
358-
fn alias_relate_direction(&self) -> ty::AliasRelationDirection;
347+
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>);
359348
}
360349

361350
fn int_unification_error<'tcx>(

compiler/rustc_infer/src/infer/relate/equate.rs

-198
This file was deleted.

compiler/rustc_infer/src/infer/relate/glb.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
151151
self.fields.register_obligations(obligations);
152152
}
153153

154-
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
155-
// FIXME(deferred_projection_equality): This isn't right, I think?
156-
ty::AliasRelationDirection::Equate
154+
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
155+
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasRelate(
156+
a.into(),
157+
b.into(),
158+
// FIXME(deferred_projection_equality): This isn't right, I think?
159+
ty::AliasRelationDirection::Equate,
160+
))]);
157161
}
158162
}

compiler/rustc_infer/src/infer/relate/lub.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
151151
self.fields.register_obligations(obligations)
152152
}
153153

154-
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
155-
// FIXME(deferred_projection_equality): This isn't right, I think?
156-
ty::AliasRelationDirection::Equate
154+
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
155+
self.register_predicates([ty::Binder::dummy(ty::PredicateKind::AliasRelate(
156+
a.into(),
157+
b.into(),
158+
// FIXME(deferred_projection_equality): This isn't right, I think?
159+
ty::AliasRelationDirection::Equate,
160+
))]);
157161
}
158162
}

compiler/rustc_infer/src/infer/relate/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
//! (except for some relations used for diagnostics and heuristics in the compiler).
33
44
pub(super) mod combine;
5-
mod equate;
65
mod generalize;
76
mod glb;
87
mod higher_ranked;
98
mod lattice;
109
mod lub;
11-
mod sub;
10+
mod type_relating;

0 commit comments

Comments
 (0)