rust-lang / rust-lang/rust

Hang in mutually recursive GAT projections involving HRTBs

Open
#149,414 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-GATs A-higher-ranked 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 (generated by a fuzzer):

trait A {
    type Item<'a>;
}

trait B {
    type Other<'a>;
}

impl<T> A for T
where
    for<'a> <T as B>::Other<'a>: Sized,
{
    type Item<'a> = <T as B>::Other<'a>;
}

impl<T> B for T
where
    for<'a> <T as A>::Item<'a>: Sized,
{
    type Other<'a> = <T as A>::Item<'a>;
}

fn main() {
    let _: for<'x> fn(&'x ()) -> <i32 as A>::Item<'x>;
}

rustc hangs (high CPU usage, no output).

Meta

rustc --version --verbose:

rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: aarch64-apple-darwin
release: 1.91.1
LLVM version: 21.1.2

On macOS, using sample on the rustc process shows it spending all its time in associated-type normalization and trait selection, repeatedly looping in:

- `rustc_trait_selection::traits::normalize::AssocTypeNormalizer::fold_predicate`
- `rustc_trait_selection::traits::normalize::normalize_trait_projection`
- `rustc_trait_selection::traits::project::opt_normalize_projection_term`
- `rustc_trait_selection::traits::select::SelectionContext::select`
- `... -> normalize_with_depth_to -> AssocTypeNormalizer::fold_predicate -> ...` (repeats)

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 minimal reproducer and profiling the associated-type normalization and trait-selection loop described in the issue. Trace the cycle through AssocTypeNormalizer::fold_predicate, normalize_trait_projection, opt_normalize_projection_term, and SelectionContext::select; done means the reproducer terminates 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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.