Rust cannot properly handle complex recursive traits
Open
Nobody has claimed this yet.
A-trait-system
C-enhancement
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
This code does not compile and compiler shows obscure diagnostic.
trait HListRec {
type Item;
type Tail: HListRec;
}
trait RecSch1: HListRec
where
<Self as HListRec>::Item: std::fmt::Debug,
<Self as HListRec>::Tail: RecSch1,
{
fn val(&self) -> String;
}
Hysterically, same idea can be expressed in swift without any issues. playground link
Any fix?
Tried this on 1.91.0-nightly.
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 linked Rust Playground reproducer using the reported nightly compiler and inspect the diagnostic for the recursive-trait example. The issue names no source file or test and does not establish whether success means accepting the code or improving the diagnostic, so the intended outcome must be clarified before work begins.
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