rust-lang / rust-lang/rust

Trait resolution fails, and then `rustc` hangs.

Open
#134,312 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-higher-ranked A-trait-system C-bug fixed-by-next-solver I-hang T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

trait Index {
    type IndexRef;
}

trait Borrow {
    type Borrowed<'a>;
}

trait Test {
    type Ref<'a>;
    type Container: Borrow where for<'a> <Self::Container as Borrow>::Borrowed<'a> : Index<IndexRef = Self::Ref<'a>>;
}

This builds fine if <Self::Container as Borrow>::Borrowed<'a> is replaced by &'a Self::Container. However, the above both errors, and also hangs rustc (still running after many minutes; wedges playground). The error is

binding for associated type Ref references lifetime 'a, which does not appear in the trait input types

I don't understand the error, though I could imagine that it is my fault or a known limitation of GATs. However, the hanging of rustc seems likely to be a bug.

Meta

rustc --version --verbose:

rustc 1.83.0 (90b35a623 2024-11-26)
Compiler output before hang

error[E0582]: binding for associated type `IndexRef` references lifetime `'a`, which does not appear in the trait input types
  --> lib.rs:11:92
   |
11 |     type Container: Borrow where for<'a> <Self::Container as Borrow>::Borrowed<'a> : Index<IndexRef = Self::Ref<'a>>;
   |                                                                                            ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

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

The reproducer is shown in the issue body at lib.rs:11; first run it with rustc 1.83.0 and confirm the E0582 diagnostic and hang. Trace trait and GAT resolution for the associated-type binding, then add or update a regression test so this input terminates without hanging.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.