Skip to content

Commit f664171

Browse files
authoredJul 6, 2024
Rollup merge of rust-lang#127405 - compiler-errors:uplift-predicate-emitting-relation, r=lcnr
uplift `PredicateEmittingRelation` Small follow-up to rust-lang#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
 

Diff for: ‎Cargo.lock

+1
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",

Diff for: ‎compiler/rustc_borrowck/src/type_check/relate_tys.rs

+5-4
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
}

Diff for: ‎compiler/rustc_infer/Cargo.toml

+1
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" }

Diff for: ‎compiler/rustc_infer/src/infer/relate/combine.rs

+5-31
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-
}

Diff for: ‎compiler/rustc_infer/src/infer/relate/generalize.rs

+2-2
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,

Diff for: ‎compiler/rustc_infer/src/infer/relate/glb.rs

+1-1
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
}

Diff for: ‎compiler/rustc_infer/src/infer/relate/lattice.rs

+1-1
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>;

Diff for: ‎compiler/rustc_infer/src/infer/relate/lub.rs

+1-1
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
}

Diff for: ‎compiler/rustc_infer/src/infer/relate/mod.rs

+3-1
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;

Diff for: ‎compiler/rustc_infer/src/infer/relate/type_relating.rs

+2-2
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
}

Diff for: ‎compiler/rustc_middle/src/ty/context.rs

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ use std::ops::{Bound, Deref};
9292
impl<'tcx> Interner for TyCtxt<'tcx> {
9393
type DefId = DefId;
9494
type LocalDefId = LocalDefId;
95+
type Span = Span;
96+
9597
type GenericArgs = ty::GenericArgsRef<'tcx>;
9698

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

Diff for: ‎compiler/rustc_middle/src/ty/relate.rs

-12
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ use crate::ty::{self as ty, Ty, TyCtxt};
1010

1111
pub type RelateResult<'tcx, T> = rustc_type_ir::relate::RelateResult<TyCtxt<'tcx>, T>;
1212

13-
/// Whether aliases should be related structurally or not. Used
14-
/// to adjust the behavior of generalization and combine.
15-
///
16-
/// This should always be `No` unless in a few special-cases when
17-
/// instantiating canonical responses and in the new solver. Each
18-
/// such case should have a comment explaining why it is used.
19-
#[derive(Debug, Copy, Clone)]
20-
pub enum StructurallyRelateAliases {
21-
Yes,
22-
No,
23-
}
24-
2513
impl<'tcx> Relate<TyCtxt<'tcx>> for ty::ImplSubject<'tcx> {
2614
#[inline]
2715
fn relate<R: TypeRelation<TyCtxt<'tcx>>>(

Diff for: ‎compiler/rustc_next_trait_solver/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
77
pub mod canonicalizer;
88
pub mod delegate;
9+
pub mod relate;
910
pub mod resolve;
1011
pub mod solve;

Diff for: ‎compiler/rustc_next_trait_solver/src/relate.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub use rustc_type_ir::relate::*;
2+
3+
pub mod combine;
4+
5+
/// Whether aliases should be related structurally or not. Used
6+
/// to adjust the behavior of generalization and combine.
7+
///
8+
/// This should always be `No` unless in a few special-cases when
9+
/// instantiating canonical responses and in the new solver. Each
10+
/// such case should have a comment explaining why it is used.
11+
#[derive(Debug, Copy, Clone)]
12+
pub enum StructurallyRelateAliases {
13+
Yes,
14+
No,
15+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pub use rustc_type_ir::relate::*;
2+
use rustc_type_ir::solve::Goal;
3+
use rustc_type_ir::{InferCtxtLike, Interner, Upcast};
4+
5+
use super::StructurallyRelateAliases;
6+
7+
pub trait PredicateEmittingRelation<Infcx, I = <Infcx as InferCtxtLike>::Interner>:
8+
TypeRelation<I>
9+
where
10+
Infcx: InferCtxtLike<Interner = I>,
11+
I: Interner,
12+
{
13+
fn span(&self) -> I::Span;
14+
15+
fn param_env(&self) -> I::ParamEnv;
16+
17+
/// Whether aliases should be related structurally. This is pretty much
18+
/// always `No` unless you're equating in some specific locations of the
19+
/// new solver. See the comments in these use-cases for more details.
20+
fn structurally_relate_aliases(&self) -> StructurallyRelateAliases;
21+
22+
/// Register obligations that must hold in order for this relation to hold
23+
fn register_goals(&mut self, obligations: impl IntoIterator<Item = Goal<I, I::Predicate>>);
24+
25+
/// Register predicates that must hold in order for this relation to hold.
26+
/// This uses the default `param_env` of the obligation.
27+
fn register_predicates(
28+
&mut self,
29+
obligations: impl IntoIterator<Item: Upcast<I, I::Predicate>>,
30+
);
31+
32+
/// Register `AliasRelate` obligation(s) that both types must be related to each other.
33+
fn register_alias_relate_predicate(&mut self, a: I::Ty, b: I::Ty);
34+
}

Diff for: ‎compiler/rustc_type_ir/src/interner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub trait Interner:
3232
{
3333
type DefId: DefId<Self>;
3434
type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
35+
type Span: Copy + Debug + Hash + Eq;
3536

3637
type GenericArgs: GenericArgs<Self>;
3738
type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;

0 commit comments

Comments
 (0)
Please sign in to comment.