Skip to content

rustc crashes with SIGSEGV when compiling a 1000 nested inline const blocks. #138547

Open
@aleksanderkrauze

Description

@aleksanderkrauze

I have generated input file containing a 1000 nested inline const blocks with following python script:

def main():
    with open("silly.rs", "w") as file:
        n = 1000
        file.write("const _: () = ")
        for _ in range(0, n):
            file.write("const { ")

        for _ in range(0, n):
            file.write("} ")

        file.write(";\n")


if __name__ == "__main__":
    main()

Then called rustc:

rustc --crate-type=lib silly.rs

Which crashes with a SIGSEGV (backtrace below).

I expected to see this happen:

I don't know really. I was just being silly and wanted to see what would happen. I know that this is an unreasonable rust code, and I was prepared for some compiler error. However seeing not even an ICE, but a full compiler crash surprised me. Setting $RUST_MIN_STACK to suggested value helps, but still this seems to be some form of a compiler bug.

I quickly searched for relevant issues, but I have not found anything similar. I have now idea if and how this should be fixed, but I thought that at least I can report it.

Meta

rustc --version --verbose:

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7
Backtrace

$ rustc --crate-type=lib silly.rs
error: rustc interrupted by SIGSEGV, printing backtrace

/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x36705c3) [0x7221174705c3]
/usr/lib/libc.so.6(+0x3dcd0) [0x722113c4bcd0]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc(+0x1475a) [0x56e2f7f6875a]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0xf4) [0x7221193a157a]

### cycle encountered after 4 frames with period 7
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4stmtNtB4_6Parser15parse_full_stmt+0x41) [0x72211939f301]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x559bb5b) [0x72211939bb5b]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x5e73f81) [0x722119c73f81]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x5560ad2) [0x722119360ad2]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(+0x55516b1) [0x7221193516b1]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4exprNtB4_6Parser21parse_expr_assoc_with+0x53) [0x72211935521f]
/home/username/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-77ea5bfe5f9d9ec5.so(_RNvMNtNtCs2a1sXFqEM9A_11rustc_parse6parser4stmtNtB4_6Parser27parse_stmt_without_recovery+0x2b66) [0x7221193a3fec]
### recursed 36 times


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
zsh: segmentation fault (core dumped)  rustc --crate-type=lib silly.rs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions