Repository navigation
Description
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.rsDeterministic (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
Vara715 commentedon Oct 6, 2026
Hey can i work on this?
xizheyin commentedon Oct 9, 2026
Vara715 commentedon Oct 9, 2026
@rustbot claim
maxdexh commentedon Oct 9, 2026
Please note the LLM Policy ^^
Rollup merge of rust-lang#164227 - Vara715:fix-rpitit-refine-cycle, r…
Unrolled build for #164227 in rollup 164430