Skip to content

Commit e0acff7

Browse files
New trait solver is a property of inference context
1 parent 3572d74 commit e0acff7

File tree

23 files changed

+61
-42
lines changed

23 files changed

+61
-42
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
285285
let infcx = self
286286
.tcx
287287
.infer_ctxt()
288-
.with_opaque_type_inference(if self.tcx.trait_solver_next() {
288+
.with_opaque_type_inference(if self.next_trait_solver() {
289289
DefiningAnchor::Bind(def_id)
290290
} else {
291291
DefiningAnchor::Bubble

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
188188

189189
// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
190190
// predefined opaques in the typeck root.
191-
if infcx.tcx.trait_solver_next() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
191+
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
192192
checker.register_predefined_opaques_in_new_solver();
193193
}
194194

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
7373
// NOTE: we may still need to normalize the built-in deref in case
7474
// we have some type like `&<Ty as Trait>::Assoc`, since users of
7575
// autoderef expect this type to have been structurally normalized.
76-
if self.infcx.tcx.trait_solver_next()
76+
if self.infcx.next_trait_solver()
7777
&& let ty::Alias(ty::Projection, _) = ty.kind()
7878
{
7979
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
156156
// In the new solver, lazy norm may allow us to shallowly equate
157157
// more types, but we emit possibly impossible-to-satisfy obligations.
158158
// Filter these cases out to make sure our coercion is more accurate.
159-
if self.tcx.trait_solver_next() {
159+
if self.next_trait_solver() {
160160
if let Ok(res) = &res {
161161
for obligation in &res.obligations {
162162
if !self.predicate_may_hold(&obligation) {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14761476
pub fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
14771477
let mut ty = self.resolve_vars_with_obligations(ty);
14781478

1479-
if self.tcx.trait_solver_next()
1479+
if self.next_trait_solver()
14801480
&& let ty::Alias(ty::Projection, _) = ty.kind()
14811481
{
14821482
match self

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
591591
.insert(opaque_type_key, hidden_type)
592592
&& last_opaque_ty.ty != hidden_type.ty
593593
{
594-
assert!(!self.tcx().trait_solver_next());
594+
assert!(!self.fcx.next_trait_solver());
595595
hidden_type
596596
.report_mismatch(&last_opaque_ty, opaque_type_key.def_id, self.tcx())
597597
.stash(
@@ -812,7 +812,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
812812

813813
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
814814
match self.fcx.fully_resolve(t) {
815-
Ok(t) if self.fcx.tcx.trait_solver_next() => {
815+
Ok(t) if self.fcx.next_trait_solver() => {
816816
// We must normalize erasing regions here, since later lints
817817
// expect that types that show up in the typeck are fully
818818
// normalized.

compiler/rustc_infer/src/infer/at.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl<'tcx> InferCtxt<'tcx> {
8282
in_snapshot: self.in_snapshot.clone(),
8383
universe: self.universe.clone(),
8484
intercrate: self.intercrate,
85+
next_trait_solver: self.next_trait_solver,
8586
}
8687
}
8788
}

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ impl<'tcx> InferCtxt<'tcx> {
109109
| (
110110
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)),
111111
ty::Alias(AliasKind::Projection, _),
112-
) if self.tcx.trait_solver_next() => {
112+
) if self.next_trait_solver() => {
113113
bug!()
114114
}
115115

116-
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.tcx.trait_solver_next() => {
116+
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.next_trait_solver() => {
117117
relation.register_type_relate_obligation(a, b);
118118
Ok(a)
119119
}
@@ -227,9 +227,22 @@ impl<'tcx> InferCtxt<'tcx> {
227227
return self.unify_const_variable(vid, a, relation.param_env());
228228
}
229229
(ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..))
230-
if self.tcx.features().generic_const_exprs || self.tcx.trait_solver_next() =>
230+
if self.tcx.features().generic_const_exprs || self.next_trait_solver() =>
231231
{
232-
relation.register_const_equate_obligation(a, b);
232+
let (a, b) = if relation.a_is_expected() { (a, b) } else { (b, a) };
233+
234+
relation.register_predicates([ty::Binder::dummy(
235+
if self.next_trait_solver() {
236+
ty::PredicateKind::AliasRelate(
237+
a.into(),
238+
b.into(),
239+
ty::AliasRelationDirection::Equate,
240+
)
241+
} else {
242+
ty::PredicateKind::ConstEquate(a, b)
243+
},
244+
)]);
245+
233246
return Ok(b);
234247
}
235248
_ => {}
@@ -453,19 +466,6 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
453466
/// be used if control over the obligation causes is required.
454467
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>);
455468

456-
/// Register an obligation that both constants must be equal to each other.
457-
///
458-
/// If they aren't equal then the relation doesn't hold.
459-
fn register_const_equate_obligation(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>) {
460-
let (a, b) = if self.a_is_expected() { (a, b) } else { (b, a) };
461-
462-
self.register_predicates([ty::Binder::dummy(if self.tcx().trait_solver_next() {
463-
ty::PredicateKind::AliasRelate(a.into(), b.into(), ty::AliasRelationDirection::Equate)
464-
} else {
465-
ty::PredicateKind::ConstEquate(a, b)
466-
})]);
467-
}
468-
469469
/// Register an obligation that both types must be related to each other according to
470470
/// the [`ty::AliasRelationDirection`] given by [`ObligationEmittingRelation::alias_relate_direction`]
471471
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {

compiler/rustc_infer/src/infer/equate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
105105
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
106106
if self.fields.define_opaque_types == DefineOpaqueTypes::Yes
107107
&& def_id.is_local()
108-
&& !self.tcx().trait_solver_next() =>
108+
&& !self.fields.infcx.next_trait_solver() =>
109109
{
110110
self.fields.obligations.extend(
111111
infcx

compiler/rustc_infer/src/infer/lattice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ where
113113
| (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }))
114114
if this.define_opaque_types() == DefineOpaqueTypes::Yes
115115
&& def_id.is_local()
116-
&& !this.tcx().trait_solver_next() =>
116+
&& !this.infcx().next_trait_solver() =>
117117
{
118118
this.register_obligations(
119119
infcx

0 commit comments

Comments
 (0)