Skip to content

Commit 1c5aed1

Browse files
Uplift PredicateEmittingRelation
1 parent 27588d1 commit 1c5aed1

File tree

16 files changed

+60
-68
lines changed

16 files changed

+60
-68
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
522522
}
523523
}
524524

525-
impl<'bccx, 'tcx> PredicateEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
525+
impl<'bccx, 'tcx> PredicateEmittingRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
526526
fn span(&self) -> Span {
527527
self.locations.span(self.type_checker.body)
528528
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub use at::DefineOpaqueTypes;
22
pub use freshen::TypeFreshener;
33
pub use lexical_region_resolve::RegionResolutionError;
44
pub use relate::combine::CombineFields;
5-
pub use relate::combine::PredicateEmittingRelation;
65
pub use relate::StructurallyRelateAliases;
76
use rustc_errors::DiagCtxtHandle;
87
pub use rustc_macros::{TypeFoldable, TypeVisitable};

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

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
use super::glb::Glb;
2222
use super::lub::Lub;
2323
use super::type_relating::TypeRelating;
24-
use super::StructurallyRelateAliases;
25-
use super::{RelateResult, TypeRelation};
26-
use crate::infer::relate;
24+
use crate::infer::relate::{
25+
self, PredicateEmittingRelation, RelateResult, StructurallyRelateAliases,
26+
};
2727
use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace};
2828
use crate::traits::{Obligation, PredicateObligation};
2929
use rustc_middle::bug;
@@ -32,7 +32,6 @@ use rustc_middle::traits::solve::Goal;
3232
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3333
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitableExt, Upcast};
3434
use rustc_middle::ty::{IntType, UintType};
35-
use rustc_span::Span;
3635

3736
#[derive(Clone)]
3837
pub struct CombineFields<'infcx, 'tcx> {
@@ -76,7 +75,7 @@ impl<'tcx> InferCtxt<'tcx> {
7675
b: Ty<'tcx>,
7776
) -> RelateResult<'tcx, Ty<'tcx>>
7877
where
79-
R: PredicateEmittingRelation<'tcx>,
78+
R: PredicateEmittingRelation<TyCtxt<'tcx>>,
8079
{
8180
debug_assert!(!a.has_escaping_bound_vars());
8281
debug_assert!(!b.has_escaping_bound_vars());
@@ -171,7 +170,7 @@ impl<'tcx> InferCtxt<'tcx> {
171170
b: ty::Const<'tcx>,
172171
) -> RelateResult<'tcx, ty::Const<'tcx>>
173172
where
174-
R: PredicateEmittingRelation<'tcx>,
173+
R: PredicateEmittingRelation<TyCtxt<'tcx>>,
175174
{
176175
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b);
177176
debug_assert!(!a.has_escaping_bound_vars());
@@ -323,30 +322,3 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
323322
)
324323
}
325324
}
326-
327-
pub trait PredicateEmittingRelation<'tcx>: TypeRelation<TyCtxt<'tcx>> {
328-
fn span(&self) -> Span;
329-
330-
fn param_env(&self) -> ty::ParamEnv<'tcx>;
331-
332-
/// Whether aliases should be related structurally. This is pretty much
333-
/// always `No` unless you're equating in some specific locations of the
334-
/// new solver. See the comments in these use-cases for more details.
335-
fn structurally_relate_aliases(&self) -> StructurallyRelateAliases;
336-
337-
/// Register obligations that must hold in order for this relation to hold
338-
fn register_goals(
339-
&mut self,
340-
obligations: impl IntoIterator<Item = Goal<'tcx, ty::Predicate<'tcx>>>,
341-
);
342-
343-
/// Register predicates that must hold in order for this relation to hold.
344-
/// This uses the default `param_env` of the obligation.
345-
fn register_predicates(
346-
&mut self,
347-
obligations: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
348-
);
349-
350-
/// Register `AliasRelate` obligation(s) that both types must be related to each other.
351-
fn register_alias_relate_predicate(&mut self, a: Ty<'tcx>, b: Ty<'tcx>);
352-
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'tcx> InferCtxt<'tcx> {
3030
/// `TypeRelation`. Do not use this, and instead please use `At::eq`, for all
3131
/// other usecases (i.e. setting the value of a type var).
3232
#[instrument(level = "debug", skip(self, relation))]
33-
pub fn instantiate_ty_var<R: PredicateEmittingRelation<'tcx>>(
33+
pub fn instantiate_ty_var<R: PredicateEmittingRelation<TyCtxt<'tcx>>>(
3434
&self,
3535
relation: &mut R,
3636
target_is_expected: bool,
@@ -178,7 +178,7 @@ impl<'tcx> InferCtxt<'tcx> {
178178
///
179179
/// See `tests/ui/const-generics/occurs-check/` for more examples where this is relevant.
180180
#[instrument(level = "debug", skip(self, relation))]
181-
pub(super) fn instantiate_const_var<R: PredicateEmittingRelation<'tcx>>(
181+
pub(super) fn instantiate_const_var<R: PredicateEmittingRelation<TyCtxt<'tcx>>>(
182182
&self,
183183
relation: &mut R,
184184
target_is_expected: bool,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Greatest lower bound. See [`lattice`].
22
33
use rustc_middle::traits::solve::Goal;
4-
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
4+
use rustc_middle::ty::relate::{PredicateEmittingRelation, Relate, RelateResult, TypeRelation};
55
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
66
use rustc_span::Span;
77

8-
use super::combine::{CombineFields, PredicateEmittingRelation};
8+
use super::combine::CombineFields;
99
use super::lattice::{self, LatticeDir};
1010
use super::StructurallyRelateAliases;
1111
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
@@ -123,7 +123,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Glb<'combine, 'infcx,
123123
}
124124
}
125125

126-
impl<'tcx> PredicateEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
126+
impl<'tcx> PredicateEmittingRelation<TyCtxt<'tcx>> for Glb<'_, '_, 'tcx> {
127127
fn span(&self) -> Span {
128128
self.fields.trace.span()
129129
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@
1717
//!
1818
//! [lattices]: https://en.wikipedia.org/wiki/Lattice_(order)
1919
20-
use super::combine::PredicateEmittingRelation;
2120
use crate::infer::{DefineOpaqueTypes, InferCtxt};
2221
use crate::traits::ObligationCause;
2322

24-
use rustc_middle::ty::relate::RelateResult;
23+
use rustc_middle::ty::relate::{PredicateEmittingRelation, RelateResult};
2524
use rustc_middle::ty::TyVar;
26-
use rustc_middle::ty::{self, Ty};
25+
use rustc_middle::ty::{self, Ty, TyCtxt};
2726

2827
/// Trait for returning data about a lattice, and for abstracting
2928
/// over the "direction" of the lattice operation (LUB/GLB).
3029
///
3130
/// GLB moves "down" the lattice (to smaller values); LUB moves
3231
/// "up" the lattice (to bigger values).
33-
pub trait LatticeDir<'f, 'tcx>: PredicateEmittingRelation<'tcx> {
32+
pub trait LatticeDir<'f, 'tcx>: PredicateEmittingRelation<TyCtxt<'tcx>> {
3433
fn infcx(&self) -> &'f InferCtxt<'tcx>;
3534

3635
fn cause(&self) -> &ObligationCause<'tcx>;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Least upper bound. See [`lattice`].
22
3-
use super::combine::{CombineFields, PredicateEmittingRelation};
3+
use super::combine::CombineFields;
44
use super::lattice::{self, LatticeDir};
55
use super::StructurallyRelateAliases;
66
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
77
use crate::traits::ObligationCause;
88

99
use rustc_middle::traits::solve::Goal;
10-
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
10+
use rustc_middle::ty::relate::{PredicateEmittingRelation, Relate, RelateResult, TypeRelation};
1111
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
1212
use rustc_span::Span;
1313

@@ -123,7 +123,7 @@ impl<'combine, 'infcx, 'tcx> LatticeDir<'infcx, 'tcx> for Lub<'combine, 'infcx,
123123
}
124124
}
125125

126-
impl<'tcx> PredicateEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
126+
impl<'tcx> PredicateEmittingRelation<TyCtxt<'tcx>> for Lub<'_, '_, 'tcx> {
127127
fn span(&self) -> Span {
128128
self.fields.trace.span()
129129
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
pub use rustc_middle::ty::relate::*;
66

77
pub use self::combine::CombineFields;
8-
pub use self::combine::PredicateEmittingRelation;
98

109
pub(super) mod combine;
1110
mod generalize;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
296296
}
297297
}
298298

299-
impl<'tcx> PredicateEmittingRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
299+
impl<'tcx> PredicateEmittingRelation<TyCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
300300
fn span(&self) -> Span {
301301
self.fields.trace.span()
302302
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9393
type DefId = DefId;
9494
type LocalDefId = LocalDefId;
9595
type GenericArgs = ty::GenericArgsRef<'tcx>;
96+
type Span = Span;
9697

9798
type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
9899
type GenericArg = ty::GenericArg<'tcx>;

0 commit comments

Comments
 (0)