rust-lang / rust-lang/rust

Compiler hangs when evaluating where clause with self-referential dyn Trait

Open
#151,671 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-hang needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

trait Specializable {}
trait C {
    type Y;
}
impl<'a, A: ?Sized + 'a> Specializable for A
where
    ( C<Y = (A, A)> + 'a): Specializable, 
{}
fn main(){}
Release channel Result
Current Stable Hang
Current Nightly (default solver) Hang
Current Nightly (+ -Znext-solver=globally) error
Meta

rustc --version --verbose:

rustc 1.95.0-nightly (d222ddc4d 2026-01-23)
binary: rustc
commit-hash: d222ddc4d90743dfc1e53b610be8fc9d95893d2c
commit-date: 2026-01-23
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8
Backtrace

warning: unnecessary parentheses around type
 --> bug.rs:7:5
  |
7 |     ( C<Y = (A, A)> + 'a): Specializable, 
  |     ^^                  ^
  |
  = note: `#[warn(unused_parens)]` (part of `#[warn(unused)]`) on by default
help: remove these parentheses
  |
7 -     ( C<Y = (A, A)> + 'a): Specializable, 
7 +     C<Y = (A, A)> + 'a : Specializable, 
  |

warning: trait objects without an explicit `dyn` are deprecated
 --> bug.rs:7:7
  |
7 |     ( C<Y = (A, A)> + 'a): Specializable, 
  |       ^^^^^^^^^^^^^^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
help: if this is a dyn-compatible trait, use `dyn`
  |
7 |     ( dyn C<Y = (A, A)> + 'a): Specializable, 
  |       +++

then 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

Reproduce the hang using the code shown as bug.rs with the stable and nightly compilers, then compare it with nightly using -Znext-solver=globally, which reports an error. Trace the compiler's trait-object, associated-type, and where-clause evaluation path; done means the default solver no longer hangs on this example.

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.