rust-lang / rust-lang/rust

Rust cannot properly handle complex recursive traits

Open
#145,245 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.