Skip to content

Commit 36182f1

Browse files
authored
Rollup merge of rust-lang#115355 - lqd:issue-115351, r=compiler-errors
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 rust-lang#115351.
2 parents 58c6907 + 325b585 commit 36182f1

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ pub(super) struct SearchGraph<'tcx> {
5151

5252
impl<'tcx> SearchGraph<'tcx> {
5353
pub(super) fn new(tcx: TyCtxt<'tcx>, mode: SolverMode) -> SearchGraph<'tcx> {
54+
let local_overflow_limit = {
55+
let recursion_limit = tcx.recursion_limit().0;
56+
if recursion_limit == 0 { 0 } else { recursion_limit.ilog2() as usize }
57+
};
5458
Self {
5559
mode,
56-
local_overflow_limit: tcx.recursion_limit().0.ilog2() as usize,
60+
local_overflow_limit,
5761
stack: Default::default(),
5862
provisional_cache: ProvisionalCache::empty(),
5963
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//~ ERROR overflow evaluating the requirement `Self well-formed`
2+
//~| ERROR overflow evaluating the requirement `Self: Trait`
3+
4+
// This is a non-regression test for issue #115351, where a recursion limit of 0 caused an ICE.
5+
// compile-flags: -Ztrait-solver=next --crate-type=lib
6+
// check-fail
7+
8+
#![recursion_limit = "0"]
9+
trait Trait {}
10+
impl Trait for u32 {}
11+
//~^ ERROR overflow evaluating the requirement `u32: Trait`
12+
//~| ERROR overflow evaluating the requirement `u32 well-formed`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0275]: overflow evaluating the requirement `Self: Trait`
2+
|
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)
4+
5+
error[E0275]: overflow evaluating the requirement `Self well-formed`
6+
|
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)
8+
9+
error[E0275]: overflow evaluating the requirement `u32: Trait`
10+
--> $DIR/recursion-limit-zero-issue-115351.rs:10:16
11+
|
12+
LL | impl Trait for u32 {}
13+
| ^^^
14+
|
15+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)
16+
17+
error[E0275]: overflow evaluating the requirement `u32 well-formed`
18+
--> $DIR/recursion-limit-zero-issue-115351.rs:10:16
19+
|
20+
LL | impl Trait for u32 {}
21+
| ^^^
22+
|
23+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`recursion_limit_zero_issue_115351`)
24+
25+
error: aborting due to 4 previous errors
26+
27+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)