overflow evaluating the requirement unless -Znext-solver is used
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
I tried this code (experimenting with type level programming). I'm not too familiar with how the trait solver works, but my guess is that instead of selecting one of the non-recursive (Or, bool, bool) impls to satisfy (Or, T, T): Redex or something, it tries the <ABits, BBits>(Or, (BigInt, ABits), (BigInt, BBits)) impl instead and recurses forever. I hit a compile error on stable and nightly, but it works on nightly with -Znext-solver.
pub trait Redex {
type Reduced;
}
pub type Reduce<T> = <T as Redex>::Reduced;
struct False;
struct True;
struct Or;
struct Nil;
struct Cons;
struct BigInt;
struct BigIntOr;
struct Foo;
struct Bar;
// Truth table for boolean Or.
impl Redex for (Or, False, False) {
type Reduced = False;
}
impl Redex for (Or, False, True) {
type Reduced = True;
}
impl Redex for (Or, True, False) {
type Reduced = True;
}
impl Redex for (Or, True, True) {
type Reduced = True;
}
// Encode integers as (BigInt, <list of bool>), and overload Or to be bitwise or.
impl<ABits, BBits> Redex for (Or, (BigInt, ABits), (BigInt, BBits))
where
(BigIntOr, ABits, BBits): Redex,
{
type Reduced = (BigInt, Reduce<(BigIntOr, ABits, BBits)>);
}
impl Redex for (BigIntOr, Nil, Nil) {
type Reduced = Nil;
}
impl<BHead, BTail> Redex for (BigIntOr, Nil, (Cons, BHead, BTail)) {
type Reduced = (Cons, BHead, BTail);
}
impl<AHead, ATail> Redex for (BigIntOr, (Cons, AHead, ATail), Nil) {
type Reduced = (Cons, AHead, ATail);
}
impl<AHead, ATail, BHead, BTail> Redex
for (BigIntOr, (Cons, AHead, ATail), (Cons, BHead, BTail))
where
(Or, AHead, ATail): Redex,
(BigIntOr, ATail, BTail): Redex,
{
type Reduced = (
Cons,
Reduce<(Or, AHead, ATail)>,
Reduce<(BigIntOr, ATail, BTail)>,
);
}
// Foo and Bar are minimal reproducers; they don't represent anything in particular.
impl<T> Redex for (Foo, T)
where
(Or, T, T): Redex,
(Or, Reduce<(Or, T, T)>, Reduce<(Or, T, T)>): Redex,
(
Or,
True,
Reduce<(Or, Reduce<(Or, T, T)>, Reduce<(Or, T, T)>)>,
): Redex,
{
type Reduced = Reduce<(
Or,
True,
Reduce<(Or, Reduce<(Or, T, T)>, Reduce<(Or, T, T)>)>,
)>;
}
impl<T> Redex for (Bar, T)
where
(Foo, T): Redex,
{
type Reduced = Reduce<(Foo, T)>;
}
fn main() {}
I expected to see this happen: code compiles successfully
Instead, this happened:
error[E0275]: overflow evaluating the requirement `(Or, (BigInt, _), (BigInt, _)): Redex`
--> crates/typestd/src/lib.rs:76:20
|
76 | type Reduced = Reduce<(Foo, T)>;
| ^^^^^^^^^^^^^^^^
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`lib`)
note: required for `(BigIntOr, (Cons, (BigInt, _), (BigInt, _)), (Cons, _, _))` to implement `Redex`
--> crates/typestd/src/lib.rs:44:34
|
44 | impl<AHead, ATail, BHead, BTail> Redex
| ^^^^^
45 | for (BigIntOr, (Cons, AHead, ATail), (Cons, BHead, BTail))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46 | where
47 | (Or, AHead, ATail): Redex,
| ----- unsatisfied trait bound introduced here
= note: 126 redundant requirements hidden
= note: required for `(Foo, T)` to implement `Redex`
However, the code compiles successfully with -Znext-solver on nightly.
Meta
rustc --version --verbose:
rustc 1.93.1 (01f6ddf75 2026-02-11)
binary: rustc
commit-hash: 01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf
commit-date: 2026-02-11
host: aarch64-unknown-linux-gnu
release: 1.93.1
LLVM version: 21.1.8
rustc 1.97.0-nightly (507271bc1 2026-05-17)
binary: rustc
commit-hash: 507271bc119683008ec719ecee48814e8ac86c65
commit-date: 2026-05-17
host: aarch64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproducer in crates/typestd/src/lib.rs and run it with stable, nightly, and nightly using -Znext-solver. Compare the trait-solver behavior around the reported overflow requirement; done means the repro no longer overflows while preserving the successful -Znext-solver result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100