rust-lang / rust-lang/rust

Hang in trait resolution with recursive blanket impl for slices

Open
#150,858 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

This issue was discovered by a fuzzer that generates code by adding a trait bound(T: Set). The compiler hangs indefinitely (consuming high CPU) when compiling the following code.

I tried this code:

trait Set<T> {
    fn contains(&self, _: T) -> bool;
    fn set(&mut self, _: T);
}
impl<'a, T: Set, S> Set<&'a [T]> for S
where
    T: Copy,
    S: Set<T>,
{
    fn contains(&self, bits: &[T]) -> bool {
        bits.iter().all(|&bit| self.contains(bit))
    }
    fn set(&mut self, bits: &[T]) {
        for &bit in bits {
            self.set(bit)
        }
    }
}
fn main() {
    let bits: &[_] = &[0, 1];
    0.contains(bits);
}

I expected to see this happen: The compiler should terminate. It should emit a compilation error

Instead, this happened: The rustc process hangs indefinitely, consuming high CPU.

Meta

rustc --version --verbose:

rustc 1.94.0-nightly (e29fcf45e 2026-01-04)
binary: rustc
commit-hash: e29fcf45e4ae686d77b490bf07320f0d3a2cf35f
commit-date: 2026-01-04
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8
Backtrace

Compiler hang

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 provided recursive blanket-impl example with the reported nightly rustc version and confirm that trait resolution hangs. Investigate the compiler's trait-resolution handling for this case, then add coverage that ensures compilation terminates with an error rather than consuming high CPU.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.