From 0e1e964a349681504e7103d4ec70aca5616222fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 29 Aug 2023 19:02:24 +0000 Subject: [PATCH 1/2] handle edge-case of a recursion limit of 0 --- compiler/rustc_trait_selection/src/solve/search_graph/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs b/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs index 49ebfa4e6cbc..52a11abd545d 100644 --- a/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/search_graph/mod.rs @@ -53,7 +53,7 @@ impl<'tcx> SearchGraph<'tcx> { pub(super) fn new(tcx: TyCtxt<'tcx>, mode: SolverMode) -> SearchGraph<'tcx> { Self { mode, - local_overflow_limit: tcx.recursion_limit().0.ilog2() as usize, + local_overflow_limit: tcx.recursion_limit().0.checked_ilog2().unwrap_or(0) as usize, stack: Default::default(), provisional_cache: ProvisionalCache::empty(), } From eefa07d69baad3207ad520da8590fb44ef989416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 29 Aug 2023 19:03:08 +0000 Subject: [PATCH 2/2] add non-regression test for issue 115351 --- .../recursion-limit-zero-issue-115351.rs | 12 +++++++++ .../recursion-limit-zero-issue-115351.stderr | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs create mode 100644 tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr diff --git a/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs new file mode 100644 index 000000000000..539c9614e828 --- /dev/null +++ b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.rs @@ -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` diff --git a/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr new file mode 100644 index 000000000000..16b25d90acec --- /dev/null +++ b/tests/ui/traits/new-solver/overflow/recursion-limit-zero-issue-115351.stderr @@ -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`.