rust-lang / rust-lang/rust

Compiler freezes on trait with generic associated type

Open
#130,640 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried this code:

trait What {
    type This<'a>: 'a
    where
        for<'b> Self::This<'b>: 'a + 'b;
}

impl<T> What for T {
    type This<'a> = T where T: 'a;
}

I expected to see this happen: The compiler returning with a success (probably not) or a compilation error

Instead, this happened: Compiler freezes, cpu usage shows one core of 100% usage (infinite loop?)

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

I tried some versions between GATs stabilizing and current nightly, and all had the same behavior.

This could be a duplicate of existing similar issues, but I am not sure if that is the case.

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 by compiling the issue's minimal trait and generic-associated-type example with the reported rustc 1.81.0 version, confirming the one-core freeze. Trace the compiler path reached by this reproducer and add a regression test; done means the example terminates with a compilation result or diagnostic instead of hanging.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.