Skip to content

Commit f664171

Browse files
Rollup merge of #127405 - compiler-errors:uplift-predicate-emitting-relation, r=lcnr
uplift `PredicateEmittingRelation` Small follow-up to #127333 r? lcnr
2 parents dfc02d2 + e5d6a41 commit f664171

File tree

16 files changed

+75
-55
lines changed

16 files changed

+75
-55
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,7 @@ dependencies = [
41684168
"rustc_index",
41694169
"rustc_macros",
41704170
"rustc_middle",
4171+
"rustc_next_trait_solver",
41714172
"rustc_span",
41724173
"rustc_target",
41734174
"rustc_type_ir",

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_errors::ErrorGuaranteed;
3-
use rustc_infer::infer::relate::{PredicateEmittingRelation, StructurallyRelateAliases};
4-
use rustc_infer::infer::relate::{Relate, RelateResult, TypeRelation};
5-
use rustc_infer::infer::NllRegionVariableOrigin;
3+
use rustc_infer::infer::relate::{
4+
PredicateEmittingRelation, Relate, RelateResult, StructurallyRelateAliases, TypeRelation,
5+
};
6+
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
67
use rustc_infer::traits::solve::Goal;
78
use rustc_infer::traits::Obligation;
89
use rustc_middle::mir::ConstraintCategory;
@@ -522,7 +523,7 @@ impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx
522523
}
523524
}
524525

525-
impl<'bccx, 'tcx> PredicateEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
526+
impl<'bccx, 'tcx> PredicateEmittingRelation<InferCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
526527
fn span(&self) -> Span {
527528
self.locations.span(self.type_checker.body)
528529
}

compiler/rustc_infer/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustc_hir = { path = "../rustc_hir" }
1616
rustc_index = { path = "../rustc_index" }
1717
rustc_macros = { path = "../rustc_macros" }
1818
rustc_middle = { path = "../rustc_middle" }
19+
rustc_next_trait_solver = { path = "../rustc_next_trait_solver" }
1920
rustc_span = { path = "../rustc_span" }
2021
rustc_target = { path = "../rustc_target" }
2122
rustc_type_ir = { path = "../rustc_type_ir" }

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

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
//! On success, the LUB/GLB operations return the appropriate bound. The
1919
//! return value of `Equate` or `Sub` shouldn't really be used.
2020
21+
pub use rustc_next_trait_solver::relate::combine::*;
22+
2123
use super::glb::Glb;
2224
use super::lub::Lub;
2325
use super::type_relating::TypeRelating;
26+
use super::RelateResult;
2427
use super::StructurallyRelateAliases;
25-
use super::{RelateResult, TypeRelation};
2628
use crate::infer::relate;
2729
use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace};
2830
use crate::traits::{Obligation, PredicateObligation};
@@ -32,7 +34,6 @@ use rustc_middle::traits::solve::Goal;
3234
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3335
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeVisitableExt, Upcast};
3436
use rustc_middle::ty::{IntType, UintType};
35-
use rustc_span::Span;
3637

3738
#[derive(Clone)]
3839
pub struct CombineFields<'infcx, 'tcx> {
@@ -76,7 +77,7 @@ impl<'tcx> InferCtxt<'tcx> {
7677
b: Ty<'tcx>,
7778
) -> RelateResult<'tcx, Ty<'tcx>>
7879
where
79-
R: PredicateEmittingRelation<'tcx>,
80+
R: PredicateEmittingRelation<InferCtxt<'tcx>>,
8081
{
8182
debug_assert!(!a.has_escaping_bound_vars());
8283
debug_assert!(!b.has_escaping_bound_vars());
@@ -171,7 +172,7 @@ impl<'tcx> InferCtxt<'tcx> {
171172
b: ty::Const<'tcx>,
172173
) -> RelateResult<'tcx, ty::Const<'tcx>>
173174
where
174-
R: PredicateEmittingRelation<'tcx>,
175+
R: PredicateEmittingRelation<InferCtxt<'tcx>>,
175176
{
176177
debug!("{}.consts({:?}, {:?})", relation.tag(), a, b);
177178
debug_assert!(!a.has_escaping_bound_vars());
@@ -323,30 +324,3 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
323324
)
324325
}
325326
}
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<InferCtxt<'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<InferCtxt<'tcx>>>(
182182
&self,
183183
relation: &mut R,
184184
target_is_expected: bool,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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<InferCtxt<'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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{self, Ty};
3030
///
3131
/// GLB moves "down" the lattice (to smaller values); LUB moves
3232
/// "up" the lattice (to bigger values).
33-
pub trait LatticeDir<'f, 'tcx>: PredicateEmittingRelation<'tcx> {
33+
pub trait LatticeDir<'f, 'tcx>: PredicateEmittingRelation<InferCtxt<'tcx>> {
3434
fn infcx(&self) -> &'f InferCtxt<'tcx>;
3535

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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<InferCtxt<'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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
//! (except for some relations used for diagnostics and heuristics in the compiler).
33
//! As well as the implementation of `Relate` for interned things (`Ty`/`Const`/etc).
44
5-
pub use rustc_middle::ty::relate::*;
5+
pub use rustc_middle::ty::relate::RelateResult;
6+
pub use rustc_next_trait_solver::relate::*;
67

78
pub use self::combine::CombineFields;
89
pub use self::combine::PredicateEmittingRelation;
910

11+
#[allow(hidden_glob_reexports)]
1012
pub(super) mod combine;
1113
mod generalize;
1214
mod glb;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::combine::CombineFields;
22
use crate::infer::relate::{PredicateEmittingRelation, StructurallyRelateAliases};
33
use crate::infer::BoundRegionConversionTime::HigherRankedType;
4-
use crate::infer::{DefineOpaqueTypes, SubregionOrigin};
4+
use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin};
55
use rustc_middle::traits::solve::Goal;
66
use rustc_middle::ty::relate::{
77
relate_args_invariantly, relate_args_with_variances, Relate, RelateResult, TypeRelation,
@@ -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<InferCtxt<'tcx>> for TypeRelating<'_, '_, 'tcx> {
300300
fn span(&self) -> Span {
301301
self.fields.trace.span()
302302
}

0 commit comments

Comments
 (0)