rust-lang / rust-lang/rust

Compiler hang with nested `impl Trait` and multiple lifetime bounds in associated type

Open
#153,164 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-trait-system C-bug I-hang needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

//@compile-flags: -Znext-solver=globally
trait Cap<'a> {}
impl<T> Cap<'_> for T {}
trait IntoCapIterator {
    type Item: IntoCapIterator;
    fn into_cap_iter(self) -> Self::Item;
}
impl<'s, 'a, 'b> IntoCapIterator for &'s u8
where
    's: 'a,
    's: 'b,
{
    type Item = impl IntoIterator<Item = impl Cap<'a> + Cap<'b>>;
    fn into_cap_iter(self) -> Self::Item {
        [self]
    }
}
fn fail_early_bound<'s, 'a, 'b>(
    a: &'s u8,
) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> {
    a.into_cap_iter()
}
fn fail_late_bound<'s, 'a, 'b>(
    a: &'s u8,
    _: &'a &'s u8,
    _: &'b &'s u8,
) -> impl IntoIterator<Item = impl Cap<'a> + Cap<'b>> {
    a.into_cap_iter()
}
fn main() {}

It seems the trait solver gets trapped in an infinite cycle trying to resolve the opaque types and their recursive bounds.

Meta

rustc --version --verbose:

rustc 1.95.0-nightly (1ed488274 2026-02-25)
binary: rustc
commit-hash: 1ed488274bec5bf5cfe6bf7a1cc089abcc4ebd68
commit-date: 2026-02-25
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0
Backtrace

<backtrace>

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 Rust reproducer with -Znext-solver=globally and observe the hang while resolving the nested opaque types and lifetime bounds. Trace the trait-solver path involved in those recursive associated-type obligations; done means the reproducer no longer hangs and its behavior is covered by a regression test.

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.