rust-lang / rust-lang/rust

ICE: stack overflow with `-Ztyping-mode-borrowck` in inference

Open
#139,446 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-impl-trait A-inference C-bug I-crash requires-nightly S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

code:

//@compile-flags: -Ztyping-mode-borrowck

trait T {}

fn wrap(x: impl T) -> impl T {
    //~^ WARN function cannot return without recursing
    wrap(wrap(x))
}

fn main() {}

Version information

rustc 1.88.0-nightly (1de931283 2025-04-06)
binary: rustc
commit-hash: 1de931283df18f3af4922fe9a96adcc8936ac42e
commit-date: 2025-04-06
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Ztyping-mode-borrowck

Program output

warning: function cannot return without recursing
 --> a.rs:5:1
  |
5 | fn wrap(x: impl T) -> impl T {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
6 |     //~^ WARN function cannot return without recursing
7 |     wrap(wrap(x))
  |          ------- recursive call site
  |
  = help: a `loop` may express intention better if this is on purpose
  = note: `#[warn(unconditional_recursion)]` on by default

error: rustc interrupted by SIGSEGV, printing backtrace

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x391999f) [0x7e969231999f]
/usr/lib/libc.so.6(+0x3dcd0) [0x7e968e84bcd0]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x57e0005) [0x7e96941e0005]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x57e00de) [0x7e96941e00de]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x57e00de) [0x7e96941e00de]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMs_NtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB6_9InferCtxt18insert_hidden_type+0x34d) [0x7e9694994b9f]

### cycle encountered after 6 frames with period 12
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95d4a) [0x7e9694995d4a]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95c42) [0x7e9694995c42]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMNtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB4_9InferCtxt18handle_opaque_type+0x87) [0x7e9694995a87]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvXs_NtNtNtCs9vGWXuItzyG_11rustc_infer5infer6relate13type_relatingNtB4_12TypeRelatingINtNtCskmNsZO2KjvA_13rustc_type_ir6relate12TypeRelationNtNtNtCsjT0uPda8Ytm_12rustc_middle2ty7context6TyCtxtE3tys+0x179a) [0x7e9693b51432]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5c4dba9) [0x7e969464dba9]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMs_NtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB6_9InferCtxt18insert_hidden_type+0x21d) [0x7e9694994a6f]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95d4a) [0x7e9694995d4a]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95c42) [0x7e9694995c42]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMNtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB4_9InferCtxt18handle_opaque_type+0x87) [0x7e9694995a87]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvXs_NtNtNtCs9vGWXuItzyG_11rustc_infer5infer6relate13type_relatingNtB4_12TypeRelatingINtNtCskmNsZO2KjvA_13rustc_type_ir6relate12TypeRelationNtNtNtCsjT0uPda8Ytm_12rustc_middle2ty7context6TyCtxtE3tys+0x179a) [0x7e9693b51432]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5c4dba9) [0x7e969464dba9]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMs_NtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB6_9InferCtxt18insert_hidden_type+0x21d) [0x7e9694994a6f]
### recursed 20 times

/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95d4a) [0x7e9694995d4a]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95c42) [0x7e9694995c42]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMNtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB4_9InferCtxt18handle_opaque_type+0x87) [0x7e9694995a87]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvXs_NtNtNtCs9vGWXuItzyG_11rustc_infer5infer6relate13type_relatingNtB4_12TypeRelatingINtNtCskmNsZO2KjvA_13rustc_type_ir6relate12TypeRelationNtNtNtCsjT0uPda8Ytm_12rustc_middle2ty7context6TyCtxtE3tys+0x179a) [0x7e9693b51432]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5c4dba9) [0x7e969464dba9]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMs_NtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB6_9InferCtxt18insert_hidden_type+0x21d) [0x7e9694994a6f]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95d4a) [0x7e9694995d4a]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(+0x5f95c42) [0x7e9694995c42]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvMNtNtCs9vGWXuItzyG_11rustc_infer5infer12opaque_typesNtB4_9InferCtxt18handle_opaque_type+0x87) [0x7e9694995a87]
/home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-cf045bbab0bf32f8.so(_RNvXs_NtNtNtCs9vGWXuItzyG_11rustc_infer5infer6relate13type_relatingNtB4_12TypeRelatingINtNtCskmNsZO2KjvA_13rustc_type_ir6relate12TypeRelationNtNtNtCsjT0uPda8Ytm_12rustc_middle2ty7context6TyCtxtE3tys+0x179a) [0x7e9693b51432]

note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
note: backtrace dumped due to SIGSEGV! resuming signal
[1]    2747756 segmentation fault  rustc a.rs -Ztyping-mode-borrowck

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 crash with the provided a.rs case and -Ztyping-mode-borrowck. Start by tracing the stack frames through insert_hidden_type and handle_opaque_type in rustc_infer, then verify that the same input no longer overflows the stack or segfaults while preserving the expected recursion warning.

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.