Skip to content

Commit 3ca629d

Browse files
Uplift Goal to rustc_type_ir
1 parent 6dab210 commit 3ca629d

File tree

21 files changed

+109
-111
lines changed

21 files changed

+109
-111
lines changed

compiler/rustc_borrowck/src/type_check/canonical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
115115

116116
pub(super) fn prove_predicates(
117117
&mut self,
118-
predicates: impl IntoIterator<Item: Upcast<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug>,
118+
predicates: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + std::fmt::Debug>,
119119
locations: Locations,
120120
category: ConstraintCategory<'tcx>,
121121
) {
@@ -127,7 +127,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
127127
#[instrument(skip(self), level = "debug")]
128128
pub(super) fn prove_predicate(
129129
&mut self,
130-
predicate: impl Upcast<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
130+
predicate: impl Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>> + std::fmt::Debug,
131131
locations: Locations,
132132
category: ConstraintCategory<'tcx>,
133133
) {

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ impl<'bccx, 'tcx> ObligationEmittingRelation<'tcx> for NllTypeRelating<'_, 'bccx
548548

549549
fn register_predicates(
550550
&mut self,
551-
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
551+
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
552552
) {
553553
self.register_obligations(
554554
obligations

compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A utility module to inspect currently ambiguous obligations in the current context.
22
use crate::FnCtxt;
3-
use rustc_infer::traits::solve::Goal;
43
use rustc_infer::traits::{self, ObligationCause};
4+
use rustc_middle::traits::solve::Goal;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66
use rustc_span::Span;
77
use rustc_trait_selection::solve::inspect::ProofTreeInferCtxtExt;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
339339

340340
pub fn register_predicates(
341341
&mut self,
342-
obligations: impl IntoIterator<Item: Upcast<'tcx, ty::Predicate<'tcx>>>,
342+
obligations: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
343343
) {
344344
self.obligations.extend(obligations.into_iter().map(|to_pred| {
345345
Obligation::new(self.infcx.tcx, self.trace.cause.clone(), self.param_env, to_pred)
@@ -365,7 +365,7 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
365365
/// be used if control over the obligation causes is required.
366366
fn register_predicates(
367367
&mut self,
368-
obligations: impl IntoIterator<Item: Upcast<'tcx, ty::Predicate<'tcx>>>,
368+
obligations: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
369369
);
370370

371371
/// Register `AliasRelate` obligation(s) that both types must be related to each other.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Glb<'_, '_, 'tcx> {
142142

143143
fn register_predicates(
144144
&mut self,
145-
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
145+
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
146146
) {
147147
self.fields.register_predicates(obligations);
148148
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for Lub<'_, '_, 'tcx> {
142142

143143
fn register_predicates(
144144
&mut self,
145-
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
145+
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
146146
) {
147147
self.fields.register_predicates(obligations);
148148
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<'tcx> ObligationEmittingRelation<'tcx> for TypeRelating<'_, '_, 'tcx> {
314314

315315
fn register_predicates(
316316
&mut self,
317-
obligations: impl IntoIterator<Item: ty::Upcast<'tcx, ty::Predicate<'tcx>>>,
317+
obligations: impl IntoIterator<Item: ty::Upcast<TyCtxt<'tcx>, ty::Predicate<'tcx>>>,
318318
) {
319319
self.fields.register_predicates(obligations);
320320
}

compiler/rustc_infer/src/traits/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ impl<T: Hash> Hash for Obligation<'_, T> {
7878
}
7979
}
8080

81-
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
81+
impl<'tcx, P> From<Obligation<'tcx, P>> for ty::Goal<'tcx, P> {
8282
fn from(value: Obligation<'tcx, P>) -> Self {
83-
solve::Goal { param_env: value.param_env, predicate: value.predicate }
83+
ty::Goal { param_env: value.param_env, predicate: value.predicate }
8484
}
8585
}
8686

@@ -155,7 +155,7 @@ impl<'tcx, O> Obligation<'tcx, O> {
155155
tcx: TyCtxt<'tcx>,
156156
cause: ObligationCause<'tcx>,
157157
param_env: ty::ParamEnv<'tcx>,
158-
predicate: impl Upcast<'tcx, O>,
158+
predicate: impl Upcast<TyCtxt<'tcx>, O>,
159159
) -> Obligation<'tcx, O> {
160160
Self::with_depth(tcx, cause, 0, param_env, predicate)
161161
}
@@ -173,7 +173,7 @@ impl<'tcx, O> Obligation<'tcx, O> {
173173
cause: ObligationCause<'tcx>,
174174
recursion_depth: usize,
175175
param_env: ty::ParamEnv<'tcx>,
176-
predicate: impl Upcast<'tcx, O>,
176+
predicate: impl Upcast<TyCtxt<'tcx>, O>,
177177
) -> Obligation<'tcx, O> {
178178
let predicate = predicate.upcast(tcx);
179179
Obligation { cause, param_env, recursion_depth, predicate }
@@ -184,12 +184,16 @@ impl<'tcx, O> Obligation<'tcx, O> {
184184
span: Span,
185185
body_id: LocalDefId,
186186
param_env: ty::ParamEnv<'tcx>,
187-
trait_ref: impl Upcast<'tcx, O>,
187+
trait_ref: impl Upcast<TyCtxt<'tcx>, O>,
188188
) -> Obligation<'tcx, O> {
189189
Obligation::new(tcx, ObligationCause::misc(span, body_id), param_env, trait_ref)
190190
}
191191

192-
pub fn with<P>(&self, tcx: TyCtxt<'tcx>, value: impl Upcast<'tcx, P>) -> Obligation<'tcx, P> {
192+
pub fn with<P>(
193+
&self,
194+
tcx: TyCtxt<'tcx>,
195+
value: impl Upcast<TyCtxt<'tcx>, P>,
196+
) -> Obligation<'tcx, P> {
193197
Obligation::with_depth(tcx, self.cause.clone(), self.recursion_depth, self.param_env, value)
194198
}
195199
}

compiler/rustc_middle/src/traits/solve.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ use crate::traits::query::NoSolution;
88
use crate::traits::Canonical;
99
use crate::ty::{
1010
self, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
11-
Upcast,
1211
};
12+
// FIXME(compiler-errors): remove this import in favor of `use rustc_middle::ty::Goal`.
13+
pub use crate::ty::Goal;
1314

1415
use super::BuiltinImplSource;
1516

@@ -18,32 +19,6 @@ pub mod inspect;
1819

1920
pub use cache::{CacheData, EvaluationCache};
2021

21-
/// A goal is a statement, i.e. `predicate`, we want to prove
22-
/// given some assumptions, i.e. `param_env`.
23-
///
24-
/// Most of the time the `param_env` contains the `where`-bounds of the function
25-
/// we're currently typechecking while the `predicate` is some trait bound.
26-
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
27-
pub struct Goal<'tcx, P> {
28-
pub predicate: P,
29-
pub param_env: ty::ParamEnv<'tcx>,
30-
}
31-
32-
impl<'tcx, P> Goal<'tcx, P> {
33-
pub fn new(
34-
tcx: TyCtxt<'tcx>,
35-
param_env: ty::ParamEnv<'tcx>,
36-
predicate: impl Upcast<'tcx, P>,
37-
) -> Goal<'tcx, P> {
38-
Goal { param_env, predicate: predicate.upcast(tcx) }
39-
}
40-
41-
/// Updates the goal to one with a different `predicate` but the same `param_env`.
42-
pub fn with<Q>(self, tcx: TyCtxt<'tcx>, predicate: impl Upcast<'tcx, Q>) -> Goal<'tcx, Q> {
43-
Goal { param_env: self.param_env, predicate: predicate.upcast(tcx) }
44-
}
45-
}
46-
4722
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]
4823
pub struct Response<'tcx> {
4924
pub certainty: Certainty,

compiler/rustc_middle/src/ty/context.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,23 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
113113
type AllocId = crate::mir::interpret::AllocId;
114114

115115
type Pat = Pattern<'tcx>;
116+
116117
type Const = ty::Const<'tcx>;
117118
type AliasConst = ty::UnevaluatedConst<'tcx>;
118119
type PlaceholderConst = ty::PlaceholderConst;
119120
type ParamConst = ty::ParamConst;
120121
type BoundConst = ty::BoundVar;
121122
type ValueConst = ty::ValTree<'tcx>;
122-
123123
type ExprConst = ty::Expr<'tcx>;
124+
124125
type Region = Region<'tcx>;
125126
type EarlyParamRegion = ty::EarlyParamRegion;
126127
type LateParamRegion = ty::LateParamRegion;
127128
type BoundRegion = ty::BoundRegion;
128129
type InferRegion = ty::RegionVid;
129-
130130
type PlaceholderRegion = ty::PlaceholderRegion;
131+
132+
type ParamEnv = ty::ParamEnv<'tcx>;
131133
type Predicate = Predicate<'tcx>;
132134
type TraitPredicate = ty::TraitPredicate<'tcx>;
133135
type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;

compiler/rustc_middle/src/ty/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ pub use self::parameterized::ParameterizedOverTcx;
9797
pub use self::pattern::{Pattern, PatternKind};
9898
pub use self::predicate::{
9999
AliasTerm, Clause, ClauseKind, CoercePredicate, ExistentialPredicate,
100-
ExistentialPredicateStableCmpExt, ExistentialProjection, ExistentialTraitRef, NormalizesTo,
101-
OutlivesPredicate, PolyCoercePredicate, PolyExistentialPredicate, PolyExistentialProjection,
102-
PolyExistentialTraitRef, PolyProjectionPredicate, PolyRegionOutlivesPredicate,
103-
PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef, PolyTypeOutlivesPredicate, Predicate,
104-
PredicateKind, ProjectionPredicate, RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef,
105-
TraitPredicate, TraitRef, TypeOutlivesPredicate, Upcast,
100+
ExistentialPredicateStableCmpExt, ExistentialProjection, ExistentialTraitRef, Goal,
101+
NormalizesTo, OutlivesPredicate, PolyCoercePredicate, PolyExistentialPredicate,
102+
PolyExistentialProjection, PolyExistentialTraitRef, PolyProjectionPredicate,
103+
PolyRegionOutlivesPredicate, PolySubtypePredicate, PolyTraitPredicate, PolyTraitRef,
104+
PolyTypeOutlivesPredicate, Predicate, PredicateKind, ProjectionPredicate,
105+
RegionOutlivesPredicate, SubtypePredicate, ToPolyTraitRef, TraitPredicate, TraitRef,
106+
TypeOutlivesPredicate,
106107
};
107108
pub use self::region::{
108109
BoundRegion, BoundRegionKind, BoundRegionKind::*, EarlyParamRegion, LateParamRegion, Region,

0 commit comments

Comments
 (0)