Skip to content

Commit

Permalink
Rollup merge of #115355 - lqd:issue-115351, r=compiler-errors
Browse files Browse the repository at this point in the history
new solver: handle edge case of a recursion limit of 0

Apparently a recursion limit of 0 is possible/valid/useful/used/cute, the more you know 🌟 .

(It's somewhat interesting to me that the old solver seemingly handles this, and that the new solver currently requires a recursion limit of 2 here)

r? `@compiler-errors.`

Fixes #115351.
  • Loading branch information
matthiaskrgr committed Aug 30, 2023
2 parents 58c6907 + 325b585 commit 36182f1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_trait_selection/src/solve/search_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ pub(super) struct SearchGraph<'tcx> {

impl<'tcx> SearchGraph<'tcx> {
pub(super) fn new(tcx: TyCtxt<'tcx>, mode: SolverMode) -> SearchGraph<'tcx> {
let local_overflow_limit = {
let recursion_limit = tcx.recursion_limit().0;
if recursion_limit == 0 { 0 } else { recursion_limit.ilog2() as usize }
};
Self {
mode,
local_overflow_limit: tcx.recursion_limit().0.ilog2() as usize,
local_overflow_limit,
stack: Default::default(),
provisional_cache: ProvisionalCache::empty(),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//~ ERROR overflow evaluating the requirement `Self well-formed`
//~| ERROR overflow evaluating the requirement `Self: Trait`

// This is a non-regression test for issue #115351, where a recursion limit of 0 caused an ICE.
// compile-flags: -Ztrait-solver=next --crate-type=lib
// check-fail

#![recursion_limit = "0"]
trait Trait {}
impl Trait for u32 {}
//~^ ERROR overflow evaluating the requirement `u32: Trait`
//~| ERROR overflow evaluating the requirement `u32 well-formed`
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0275]: overflow evaluating the requirement `Self: Trait`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)

error[E0275]: overflow evaluating the requirement `Self well-formed`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)

error[E0275]: overflow evaluating the requirement `u32: Trait`
--> $DIR/recursion-limit-zero-issue-115351.rs:10:16
|
LL | impl Trait for u32 {}
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)

error[E0275]: overflow evaluating the requirement `u32 well-formed`
--> $DIR/recursion-limit-zero-issue-115351.rs:10:16
|
LL | impl Trait for u32 {}
| ^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0275`.

0 comments on commit 36182f1

Please sign in to comment.