Skip to content

Self-referential return-type-notation bound (impl Tr<m(..): Send> on Tr::m itself) overflows the stack in compare_impl_item::refine #163866

Closed

Description

@YuanchengJiang

Repo: rust-lang/rust · Commit: 837b18aae (master, 2026-10-01) · Build: stage1, rust.debug-assertions = true, llvm.assertions = true

What happens

A trait method whose RPITIT return type bounds the method's own RTN projection
(fn stream(&self) -> impl IntFactory<stream(..): Send>), once implemented, makes the
refining-impl-trait check recurse without bound. rustc segfaults on stack exhaustion after
reporting an ordinary type error:

error[E0271]: type mismatch resolving `<S as IntFactory>::stream::{opaque#0}<'_> == !`
  --> repro.rs:10:25
   |
10 |     fn stream(&self) -> impl IntFactory<stream(..): Send> {
   |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ

error: rustc interrupted by SIGSEGV, printing backtrace

librustc_driver-*.so(_ZN...rustc_hir_analysis::check::compare_impl_item::refine::ImplTraitInTraitCollector as rustc_type_ir::visit::TypeVisitor<TyCtxt>>::visit_ty+0x...)
librustc_driver-*.so(... ImplTraitInTraitCollector ... ::visit_ty+0x...)
    [the same frame repeated until the backtrace limit]
librustc_driver-*.so(<TyCtxt as rustc_type_ir::interner::Interner>::intern_bound_region+0x5d)

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
help: you can increase rustc's stack size by setting RUST_MIN_STACK=35651584

The only compiler frame in the dump is
rustc_hir_analysis::check::compare_impl_item::refine::ImplTraitInTraitCollector::visit_ty,
repeated: the collector walks the impl's return type, finds the RPITIT projection, visits
that projection's bounds (stream(..): Send), finds the same projection again, and so on.

Reproducer

repro.rs:

#![feature(return_type_notation)]

trait IntFactory {
    fn stream(&self) -> impl IntFactory<stream(..): Send>;
}

struct S;

impl IntFactory for S {
    fn stream(&self) -> impl IntFactory<stream(..): Send> {
        todo!()
    }
}

fn main() {}
rustc --emit=metadata repro.rs

Deterministic (3/3). The same overflow happens with -Znext-solver=no (then after
error[E0277]: the trait bound !: IntFactory is not satisfied), with
-Znext-solver=globally (the default in this build) and on editions 2021/2024. Without the
impl IntFactory for S block the trait declaration alone is accepted; with a default body in
the trait instead of an impl only E0275: overflow evaluating the requirement is reported,
so the unbounded recursion is specific to the refine check on an impl.

Expected

The E0271/E0277 error and aborting due to ..., or an E0275-style overflow/cycle
diagnostic for the self-referential bound. The compiler should not run out of stack.

Notes

  • Error-recovery crash: a type error is emitted first, but a stack overflow is a hard crash
    rather than a delayed bug, and the input is tiny.
  • The declaration fn stream(&self) -> impl IntFactory<stream(..): Send>; is the regression
    test for [ICE]: cycle detected when computing function signature #154056 (tests/ui/associated-type-bounds/return-type-notation/...); adding an
    impl of it is what fusion contributed.

Upstream dedup 2026-10-06: GitHub search API (return_type_notation stack overflow, ImplTraitInTraitCollector, label:I-ICE refine "stream(..)") and WebSearch (return_type_notation stack overflow ImplTraitInTraitCollector refine). The only ImplTraitInTraitCollector hit is #145921 (closed 2025-08-27; panic when an async fn trait method is implemented as a non-async fn, not a recursion). Generic impl Trait stack overflows (#43263, #92833, #69096) are old and not RTN. Verdict: new.

Activity

  1. added
    C-bug
    on Oct 6, 2026
  2. added
    needs-triage
    on Oct 6, 2026
  3. Vara715 commented on Oct 6, 2026

    @Vara715
    Contributor

    Hey can i work on this?

  4. added
    I-crash
    T-compiler
    on Oct 7, 2026
  5. xizheyin commented on Oct 9, 2026

    @xizheyin
  6. Vara715 commented on Oct 9, 2026

    @Vara715
    Contributor

    @rustbot claim

  7. added
    T-types
    F-return_type_notation
    and removed
    needs-triage
    on Oct 9, 2026
  8. maxdexh commented on Oct 9, 2026

    @maxdexh
    Member

    Please note the LLM Policy ^^

  9. added a commit that references this issue on Oct 16, 2026
    6b688f0
  10. added a commit that references this issue on Oct 16, 2026
    4d6ee9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugF-return_type_notationI-crashT-compilerT-types

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions