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 3034b2b

Browse files
Combine sub and eq
1 parent 9f05da7 commit 3034b2b

File tree

8 files changed

+348
-455
lines changed

8 files changed

+348
-455
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: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//! There are four type combiners: [Equate], [Sub], [Lub], and [Glb].
1+
//! There are four type combiners: [TypeRelating], [Lub], and [Glb],
2+
//! (and `NllTypeRelating` in rustc_borrowck, which is only used for NLL).
3+
//!
24
//! Each implements the trait [TypeRelation] and contains methods for
35
//! combining two instances of various things and yielding a new instance.
46
//! These combiner methods always yield a `Result<T>`. To relate two
@@ -22,10 +24,9 @@
2224
//! [TypeRelation::a_is_expected], so when dealing with contravariance
2325
//! this should be correctly updated.
2426
25-
use super::equate::Equate;
2627
use super::glb::Glb;
2728
use super::lub::Lub;
28-
use super::sub::Sub;
29+
use super::type_relating::TypeRelating;
2930
use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace};
3031
use crate::traits::{Obligation, PredicateObligations};
3132
use rustc_middle::infer::canonical::OriginalQueryValues;
@@ -303,12 +304,12 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
303304
self.infcx.tcx
304305
}
305306

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

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

314315
pub fn lub<'a>(&'a mut self, a_is_expected: bool) -> Lub<'a, 'infcx, 'tcx> {
@@ -343,19 +344,8 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
343344
/// be used if control over the obligation causes is required.
344345
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>);
345346

346-
/// Register an obligation that both types must be related to each other according to
347-
/// 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+
/// Register `AliasRelate` obligation(s) that both types must be related to each other.
348+
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>);
359349
}
360350

361351
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 によって変換されたページ (->オリジナル) /