Skip to content

Commit 7dac755

Browse files
lcnrcompiler-errors
andcommitted
FIXME(-Znext-solver) triage
Co-authored-by: Michael Goulet <michael@errs.io>
1 parent c68032f commit 7dac755

File tree

20 files changed

+68
-40
lines changed

20 files changed

+68
-40
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
141141
}
142142

143143
if !tcx.recursion_limit().value_within_limit(iteration) {
144+
// This may actually be reachable. If so, we should convert
145+
// this to a proper error/consider whether we should detect
146+
// this somewhere else.
144147
bug!(
145-
"FIXME(-Znext-solver): Overflowed when processing region obligations: {outlives_predicates:#?}"
148+
"unexpected overflowed when processing region obligations: {outlives_predicates:#?}"
146149
);
147150
}
148151

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
160160
self.param_env,
161161
ty::Binder::dummy(trait_ref),
162162
);
163-
if !self.infcx.predicate_may_hold(&obligation) {
163+
if !self.infcx.next_trait_solver() && !self.infcx.predicate_may_hold(&obligation) {
164164
debug!("overloaded_deref_ty: cannot match obligation");
165165
return None;
166166
}
@@ -184,17 +184,17 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
184184
self.param_env,
185185
ty,
186186
) else {
187-
// We shouldn't have errors here, except for evaluate/fulfill mismatches,
188-
// but that's not a reason for an ICE (`predicate_may_hold` is conservative
189-
// by design).
190-
// FIXME(-Znext-solver): This *actually* shouldn't happen then.
187+
// We shouldn't have errors here in the old solver, except for
188+
// evaluate/fulfill mismatches, but that's not a reason for an ICE.
191189
return None;
192190
};
193191
let errors = ocx.select_where_possible();
194192
if !errors.is_empty() {
195-
// This shouldn't happen, except for evaluate/fulfill mismatches,
196-
// but that's not a reason for an ICE (`predicate_may_hold` is conservative
197-
// by design).
193+
if self.infcx.next_trait_solver() {
194+
unreachable!();
195+
}
196+
// We shouldn't have errors here in the old solver, except for
197+
// evaluate/fulfill mismatches, but that's not a reason for an ICE.
198198
debug!(?errors, "encountered errors while fulfilling");
199199
return None;
200200
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
805805
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
806806
});
807807
let bound = (bound.upcast(tcx), span);
808-
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
808+
// FIXME(-Znext-solver): We can likely remove this hack once the
809+
// new trait solver lands. This fixed an overflow in the old solver.
810+
// This may have performance implications, so please check perf when
811+
// removing it.
812+
// This was added in <https://github.com/rust-lang/rust/pull/123302>.
809813
if tcx.is_lang_item(trait_def_id, rustc_hir::LangItem::Sized) {
810814
bounds.insert(0, bound);
811815
} else {

compiler/rustc_hir_typeck/src/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
600600
let (def_id, args) = match *expected_ty.kind() {
601601
// FIXME: Could also check that the RPIT is not defined
602602
ty::Alias(ty::Opaque, alias_ty) => (alias_ty.def_id.as_local()?, alias_ty.args),
603-
// FIXME(-Znext-solver): Remove this branch once `replace_opaque_types_with_infer` is gone.
603+
// FIXME(-Znext-solver=no): Remove this branch once `replace_opaque_types_with_infer` is gone.
604604
ty::Infer(ty::TyVar(_)) => self
605605
.inner
606606
.borrow_mut()

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
260260
mut expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
261261
allow_two_phase: AllowTwoPhase,
262262
) -> Result<Ty<'tcx>, Diag<'a>> {
263-
let expected = self.resolve_vars_with_obligations(expected);
263+
let expected = if self.next_trait_solver() {
264+
expected
265+
} else {
266+
self.resolve_vars_with_obligations(expected)
267+
};
264268

265269
let e = match self.coerce(expr, checked_ty, expected, allow_two_phase, None) {
266270
Ok(ty) => return Ok(ty),

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,8 +1436,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14361436
/// in this case.
14371437
#[instrument(level = "debug", skip(self, sp), ret)]
14381438
pub(crate) fn try_structurally_resolve_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
1439-
let ty = self.resolve_vars_with_obligations(ty);
1440-
14411439
if self.next_trait_solver()
14421440
&& let ty::Alias(..) = ty.kind()
14431441
{
@@ -1455,7 +1453,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14551453
}
14561454
}
14571455
} else {
1458-
ty
1456+
self.resolve_vars_with_obligations(ty)
14591457
}
14601458
}
14611459

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ pub(crate) struct LoweredTy<'tcx> {
412412

413413
impl<'tcx> LoweredTy<'tcx> {
414414
fn from_raw(fcx: &FnCtxt<'_, 'tcx>, span: Span, raw: Ty<'tcx>) -> LoweredTy<'tcx> {
415-
// FIXME(-Znext-solver): We're still figuring out how to best handle
416-
// normalization and this doesn't feel too great. We should look at this
417-
// code again before stabilizing it.
415+
// FIXME(-Znext-solver=no): This is easier than requiring all uses of `LoweredTy`
416+
// to call `try_structurally_resolve_type` instead. This seems like a lot of
417+
// effort, especially as we're still supporting the old solver. We may revisit
418+
// this in the future.
418419
let normalized = if fcx.next_trait_solver() {
419420
fcx.try_structurally_resolve_type(span, raw)
420421
} else {

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,8 +1913,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19131913
ty::Binder::dummy(trait_ref),
19141914
);
19151915

1916-
// FIXME(-Znext-solver): We only need this hack to deal with fatal
1917-
// overflow in the old solver.
1916+
// We only need this hack to deal with fatal overflow in the old solver.
19181917
if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
19191918
{
19201919
ocx.register_obligation(obligation);
@@ -1955,17 +1954,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19551954
}
19561955
}
19571956

1958-
// FIXME(-Znext-solver): See the linked issue below.
1959-
// <https://github.com/rust-lang/trait-system-refactor-initiative/issues/134>
1957+
// See <https://github.com/rust-lang/trait-system-refactor-initiative/issues/134>.
19601958
//
19611959
// In the new solver, check the well-formedness of the return type.
19621960
// This emulates, in a way, the predicates that fall out of
19631961
// normalizing the return type in the old solver.
19641962
//
1965-
// We alternatively could check the predicates of the method itself hold,
1966-
// but we intentionally do not do this in the old solver b/c of cycles,
1967-
// and doing it in the new solver would be stronger. This should be fixed
1968-
// in the future, since it likely leads to much better method winnowing.
1963+
// FIXME(-Znext-solver): We alternatively could check the predicates of
1964+
// the method itself hold, but we intentionally do not do this in the old
1965+
// solver b/c of cycles, and doing it in the new solver would be stronger.
1966+
// This should be fixed in the future, since it likely leads to much better
1967+
// method winnowing.
19691968
if let Some(xform_ret_ty) = xform_ret_ty
19701969
&& self.infcx.next_trait_solver()
19711970
{

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ impl<'tcx> InferCtxt<'tcx> {
198198
}
199199

200200
if !self.tcx.recursion_limit().value_within_limit(iteration) {
201+
// This may actually be reachable. If so, we should convert
202+
// this to a proper error/consider whether we should detect
203+
// this somewhere else.
201204
bug!(
202-
"FIXME(-Znext-solver): Overflowed when processing region obligations: {my_region_obligations:#?}"
205+
"unexpected overflowed when processing region obligations: {my_region_obligations:#?}"
203206
);
204207
}
205208

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ use crate::ty::{
8686

8787
#[allow(rustc::usage_of_ty_tykind)]
8888
impl<'tcx> Interner for TyCtxt<'tcx> {
89+
fn next_trait_solver_globally(self) -> bool {
90+
self.next_trait_solver_globally()
91+
}
92+
8993
type DefId = DefId;
9094
type LocalDefId = LocalDefId;
9195
type Span = Span;

0 commit comments

Comments
 (0)