Infinite recursion in type constraint resolution
Open
Nobody has claimed this yet.
A-inference
A-trait-system
C-bug
fixed-by-next-solver
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::borrow::Borrow;
trait A {
const XXX: usize = 1;
}
struct Special<U>(U);
struct Wrapper<T, const N: usize>([T; N]);
impl<T, const N: usize> A for Special<Wrapper<T, N>>
where
Special<T>: A
{}
impl<T: Borrow<str>> A for Special<T> {
}
fn main() {
let _ = <Special<Wrapper<String, 1>> as A>::XXX;
}
I expected to see this happen: the code should compile
Instead, this happened:
error[E0275]: overflow evaluating the requirement `Special<Wrapper<_, _>>: A`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`blah`)
note: required for `Special<Wrapper<Wrapper<_, _>, _>>` to implement `A`
--> blah.rs:11:25
|
11 | impl<T, const N: usize> A for Special<Wrapper<T, N>>
| ^ ^^^^^^^^^^^^^^^^^^^^^^
12 | where
13 | Special<T>: A
| - unsatisfied trait bound introduced here
= note: 126 redundant requirements hidden
= note: required for `Special<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<..., _>, _>, _>, _>, _>>` to implement `A`
= note: the full name for the type has been written to 'blah.long-type-12463274173695242483.txt'
= note: consider using `--verbose` to print the full type name to the console
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0275`.
Meta
rustc --version --verbose:
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Backtrace
error[E0275]: overflow evaluating the requirement `Special<Wrapper<_, _>>: A`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`blah`)
note: required for `Special<Wrapper<Wrapper<_, _>, _>>` to implement `A`
--> blah.rs:11:25
|
11 | impl<T, const N: usize> A for Special<Wrapper<T, N>>
| ^ ^^^^^^^^^^^^^^^^^^^^^^
12 | where
13 | Special<T>: A
| - unsatisfied trait bound introduced here
= note: 126 redundant requirements hidden
= note: required for `Special<Wrapper<Wrapper<Wrapper<Wrapper<Wrapper<..., _>, _>, _>, _>, _>>` to implement `A`
= note: the full name for the type has been written to 'blah.long-type-12463274173695242483.txt'
= note: consider using `--verbose` to print the full type name to the console
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0275`.
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 by compiling the reproducer in blah.rs with the reported rustc 1.78.0 toolchain and confirm the E0275 overflow. Then investigate the compiler's type constraint resolution path; done means the reproducer no longer produces the unintended infinite recursion while preserving the expected trait behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100