Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6ccca8c

Browse files
Combine sub and eq
1 parent 9f05da7 commit 6ccca8c

File tree

8 files changed

+344
-452
lines changed

8 files changed

+344
-452
lines changed

‎compiler/rustc_borrowck/src/type_check/relate_tys.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,15 @@ impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
348348

349349
debug!(?self.ambient_variance);
350350
// In a bivariant context this always succeeds.
351-
let r =
352-
if self.ambient_variance == ty::Variance::Bivariant { a } else { self.relate(a, b)? };
351+
let r = if self.ambient_variance == ty::Variance::Bivariant {
352+
Ok(a)
353+
} else {
354+
self.relate(a, b)
355+
};
353356

354357
self.ambient_variance = old_ambient_variance;
355358

356-
Ok(r)
359+
r
357360
}
358361

359362
#[instrument(skip(self), level = "debug")]
@@ -576,10 +579,6 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx
576579
);
577580
}
578581

579-
fn alias_relate_direction(&self) -> ty::AliasRelationDirection {
580-
unreachable!("manually overridden to handle ty::Variance::Contravariant ambient variance")
581-
}
582-
583582
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {
584583
self.register_predicates([ty::Binder::dummy(match self.ambient_variance {
585584
ty::Variance::Covariant => ty::PredicateKind::AliasRelate(

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

Lines changed: 6 additions & 17 deletions
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‎

Lines changed: 0 additions & 198 deletions
This file was deleted.

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

Lines changed: 7 additions & 3 deletions
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‎

Lines changed: 7 additions & 3 deletions
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‎

Lines changed: 1 addition & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /