Skip to content

Commit bdb04d6

Browse files
committed
Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU
`FIXME(-Znext-solver)` triage r? `@BoxyUwU`
2 parents 0a39445 + 7dac755 commit bdb04d6

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;

compiler/rustc_mir_transform/src/inline/cycle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
138138
}
139139
false
140140
}
141-
// FIXME(-Znext-solver): Remove this hack when trait solver overflow can return an error.
141+
// FIXME(-Znext-solver=no): Remove this hack when trait solver overflow can return an error.
142142
// In code like that pointed out in #128887, the type complexity we ask the solver to deal with
143143
// grows as we recurse into the call graph. If we use the same recursion limit here and in the
144144
// solver, the solver hits the limit first and emits a fatal error. But if we use a reduced

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ where
237237
return None;
238238
}
239239

240-
// FIXME(-Znext-solver): We should instead try to find a `Certainty::Yes` response with
241-
// a subset of the constraints that all the other responses have.
240+
// FIXME(-Znext-solver): Add support to merge region constraints in
241+
// responses to deal with trait-system-refactor-initiative#27.
242242
let one = responses[0];
243243
if responses[1..].iter().all(|&resp| resp == one) {
244244
return Some(one);

compiler/rustc_next_trait_solver/src/solve/normalizes_to/inherent.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ where
4141
// and we tag the impl bounds with `GoalSource::ImplWhereBound`?
4242
// Right now this includes both the impl and the assoc item where bounds,
4343
// and I don't think the assoc item where-bounds are allowed to be coinductive.
44+
//
45+
// Projecting to the IAT also "steps out the impl contructor", so we would have
46+
// to be very careful when changing the impl where-clauses to be productive.
4447
self.add_goals(
4548
GoalSource::Misc,
4649
cx.predicates_of(inherent.def_id)

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ where
235235
.predicates_of(goal.predicate.def_id())
236236
.iter_instantiated(cx, goal.predicate.trait_ref.args)
237237
.map(|p| goal.with(cx, p));
238-
// FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
238+
// While you could think of trait aliases to have a single builtin impl
239+
// which uses its implied trait bounds as where-clauses, using
240+
// `GoalSource::ImplWhereClause` here would be incorrect, as we also
241+
// impl them, which means we're "stepping out of the impl constructor"
242+
// again. To handle this, we treat these cycles as ambiguous for now.
239243
ecx.add_goals(GoalSource::Misc, nested_obligations);
240244
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
241245
})

compiler/rustc_trait_selection/src/traits/normalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'tcx> At<'_, 'tcx> {
4747
/// same goals in both a temporary and the shared context which negatively impacts
4848
/// performance as these don't share caching.
4949
///
50-
/// FIXME(-Znext-solver): For performance reasons, we currently reuse an existing
50+
/// FIXME(-Znext-solver=no): For performance reasons, we currently reuse an existing
5151
/// fulfillment context in the old solver. Once we have removed the old solver, we
5252
/// can remove the `fulfill_cx` parameter on this function.
5353
fn deeply_normalize<T, E>(

compiler/rustc_traits/src/codegen.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pub(crate) fn codegen_select_candidate<'tcx>(
5858
// Currently, we use a fulfillment context to completely resolve
5959
// all nested obligations. This is because they can inform the
6060
// inference of the impl's type parameters.
61-
// FIXME(-Znext-solver): Doesn't need diagnostics if new solver.
6261
let ocx = ObligationCtxt::new(&infcx);
6362
let impl_source = selection.map(|obligation| {
6463
ocx.register_obligation(obligation);

compiler/rustc_type_ir/src/fast_reject.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub enum TreatParams {
8484
///
8585
/// This also treats projections with inference variables as infer vars
8686
/// since they could be further normalized.
87+
// FIXME(@lcnr): This treats aliases as rigid. This is only correct if the
88+
// type has been structurally normalized. We should reflect this requirement
89+
// in the variant name. It is currently incorrectly used in diagnostics.
8790
AsRigid,
8891
}
8992

@@ -151,9 +154,11 @@ pub fn simplify_type<I: Interner>(
151154
ty::Alias(..) => match treat_params {
152155
// When treating `ty::Param` as a placeholder, projections also
153156
// don't unify with anything else as long as they are fully normalized.
154-
// FIXME(-Znext-solver): Can remove this `if` and always simplify to `Placeholder`
155-
// when the new solver is enabled by default.
156-
TreatParams::AsRigid if !ty.has_non_region_infer() => Some(SimplifiedType::Placeholder),
157+
TreatParams::AsRigid
158+
if !ty.has_non_region_infer() || cx.next_trait_solver_globally() =>
159+
{
160+
Some(SimplifiedType::Placeholder)
161+
}
157162
TreatParams::AsRigid | TreatParams::InstantiateWithInfer => None,
158163
},
159164
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),

compiler/rustc_type_ir/src/interner.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ pub trait Interner:
3232
+ IrPrint<ty::FnSig<Self>>
3333
+ IrPrint<ty::PatternKind<Self>>
3434
{
35+
fn next_trait_solver_globally(self) -> bool {
36+
true
37+
}
38+
3539
type DefId: DefId<Self>;
3640
type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
3741
type Span: Span<Self>;

tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/recursive-coroutine-boxed.rs:14:23
2+
--> $DIR/recursive-coroutine-boxed.rs:11:23
33
|
44
LL | let mut gen = Box::pin(foo());
55
| ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box`

tests/ui/impl-trait/recursive-coroutine-boxed.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use std::ops::{Coroutine, CoroutineState};
88

99
fn foo() -> impl Coroutine<Yield = (), Return = ()> {
10-
// FIXME(-Znext-solver): this fails with a mismatched types as the
11-
// hidden type of the opaque ends up as {type error}. We should not
12-
// emit errors for such goals.
1310
#[coroutine] || {
1411
let mut gen = Box::pin(foo());
1512
//[next]~^ ERROR type annotations needed

0 commit comments

Comments
 (0)