diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 156dfc4fc1e69..004d1df069d6e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -338,18 +338,6 @@ fn maybe_evaluate_root_goal_with_higher_recursion_limit( Ok(goal_evaluation) => goal_evaluation.goal.predicate, }; - // Some goals no longer overflow after the stalled infers are resolved. - // Thus we don't have to rerun eagerly here. - let has_stalled_infers = match predicate.kind().skip_binder() { - ty::PredicateKind::Clause(ty::ClauseKind::Projection(projection)) => { - projection.projection_term.has_non_region_infer() - } - _ => predicate.has_non_region_infer(), - }; - if has_stalled_infers { - return; - } - let rerun_result = delegate.commit_if_ok(|| { let rerun_result = EvalCtxt::enter_root(delegate, delegate.cx().recursion_limit() * 2, span, |ecx| { @@ -397,19 +385,6 @@ fn maybe_evaluate_root_goal_for_proof_tree_with_higher_recursion_limit( Ok(_) => {} } - // Some goals no longer overflow after the stalled infers are resolved. - // Thus we don't have to rerun eagerly here. - let predicate: I::Predicate = goal_evaluation.uncanonicalized_goal.predicate; - let has_stalled_infers = match predicate.kind().skip_binder() { - ty::PredicateKind::Clause(ty::ClauseKind::Projection(projection)) => { - projection.projection_term.has_non_region_infer() - } - _ => predicate.has_non_region_infer(), - }; - if has_stalled_infers { - return; - } - let rerun_result = delegate.commit_if_ok(|| { let (new_result, new_goal_evaluation) = evaluate_root_goal_for_proof_tree( delegate, @@ -426,6 +401,7 @@ fn maybe_evaluate_root_goal_for_proof_tree_with_higher_recursion_limit( } }); if let Ok(rerun_result) = rerun_result { + let predicate: I::Predicate = goal_evaluation.uncanonicalized_goal.predicate; delegate.cx().emit_next_solver_overflow_fcw(predicate, span); *initial_result = rerun_result; } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 022784b56d4ce..110830f101c4c 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1009,7 +1009,7 @@ pub struct NextSolverConfig { pub coherence: bool = true, /// Whether the new trait solver should be enabled everywhere. /// This is only `true` if `coherence` is also enabled. - pub globally: bool = false, + pub globally: bool = true, } #[derive(Clone)] diff --git a/tests/ui/traits/next-solver/overflow-discards-constraints.rs b/tests/ui/traits/next-solver/overflow-discards-constraints.rs new file mode 100644 index 0000000000000..a5432f40a8659 --- /dev/null +++ b/tests/ui/traits/next-solver/overflow-discards-constraints.rs @@ -0,0 +1,75 @@ +//@ compile-flags: -Znext-solver +//@ check-pass + +// Previously we didn't rerun the goal with doubled recursion limit if the goal contained ty vars. +// This is to avoid futile evaluation. However, sometimes the type inference progress relies on +// successful trait solving response. If we don't evaluate with higher recursion limit, the type +// inference would fail eventually. +// +// See the `recursion_depth_exceeding_limit` FCW for why we need the doubled recursion limit. + +// Setting it to 12 would make it compile. +#![recursion_limit = "6"] + +trait Trait {} + +struct W1(T); +struct W2(T); +struct W3(T); +struct W4(T); +struct W5(T); +struct W6(T); +struct W7(T); + + +impl Trait for () + where + W1: Trait, +{} + +impl Trait for W1 +where + W2: Trait, +{} + +impl Trait for W2 +where + W3: Trait, +{} + +impl Trait for W3 +where + W4: Trait, +{} + +impl Trait for W4 +where + W5: Trait, +{} + +impl Trait for W5 +where + W6: Trait, +{} + +impl Trait for W6 +where + W7: Trait, +{} + +impl Trait for W7 {} + +fn foo() + where + (): Trait, +{ +} + +fn main() { + foo(); // register a `(): Trait` obligation + //~^ WARN: overflow evaluating the requirement `(): Trait<_>` [recursion_depth_exceeding_limit] + //~| WARN: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + //~| WARN: overflow evaluating the requirement `(): Trait` [recursion_depth_exceeding_limit] + //~| WARN: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + +} diff --git a/tests/ui/traits/next-solver/overflow-discards-constraints.stderr b/tests/ui/traits/next-solver/overflow-discards-constraints.stderr new file mode 100644 index 0000000000000..5705b0a97e58d --- /dev/null +++ b/tests/ui/traits/next-solver/overflow-discards-constraints.stderr @@ -0,0 +1,27 @@ +warning: overflow evaluating the requirement `(): Trait<_>` + --> $DIR/overflow-discards-constraints.rs:69:5 + | +LL | foo(); // register a `(): Trait` obligation + | ^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "12"]` attribute to your crate (`overflow_discards_constraints`) + = help: or consider adding a manual `impl` of auto traits like `Send` for intermediate types, if auto traits are involved + = note: this lint is attached to the whole crate and can't be disabled on a per-function basis + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #159228 + = note: `#[warn(recursion_depth_exceeding_limit)]` (part of `#[warn(future_incompatible)]`) on by default + +warning: overflow evaluating the requirement `(): Trait` + --> $DIR/overflow-discards-constraints.rs:69:5 + | +LL | foo(); // register a `(): Trait` obligation + | ^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "12"]` attribute to your crate (`overflow_discards_constraints`) + = help: or consider adding a manual `impl` of auto traits like `Send` for intermediate types, if auto traits are involved + = note: this lint is attached to the whole crate and can't be disabled on a per-function basis + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #159228 + +warning: 2 warnings emitted +