Infinite Loop when Evaluating Recursive Type
Open
Nobody has claimed this yet.
A-associated-items
A-trait-system
C-bug
fixed-by-next-solver
I-hang
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried the code:
trait Access {
type Downcast: Access;
}
trait Mapping<X: Access> {}
trait AllowedMappingLoopback<X: Access> {
type Chain: AllowedMapping<X::Downcast>;
}
impl<X: Access> AllowedMappingLoopback<X> for X
where
X: AllowedMapping<X::Downcast>,
{
type Chain = X;
}
trait AllowedMapping<X: Access>: AllowedMappingLoopback<X, Chain = Self> {}
impl<X: Access, T> AllowedMapping<X> for T where
T: Mapping<X> + AllowedMappingLoopback<X, Chain = Self>
{
}
fn do_thing_with_allowed<X: Access>(mapping: impl AllowedMapping<X>) {}
struct BasicMapping;
fn test() {
do_thing_with_allowed(BasicMapping);
}
This results in an infinite loop within the compiler, within both the latest nightly (1.78.0 (2024-03-12)) and stable (1.76.0).
(see playground)
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
The issue provides a Rust reproducer and a Rust Playground link; start by running it on stable and nightly to confirm the infinite loop while evaluating the recursive trait bounds. Trace the compiler's evaluation of those bounds and finish when the example terminates without looping, with appropriate regression coverage identified during investigation.
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
- Mostly clear
- Newbie friendliness
- 30/100