Skip to content

Using a reference to a self-referential static as a pattern causes stack overflow #144719

@theemathas

Description

@theemathas

Code

This code causes rustc to crash with a stack overflow.

#[derive(PartialEq)]
struct Thing(&'static Thing);

static X: Thing = Thing(&X);

const Y: &Thing = &X;

fn main() {
    if let Y = Y {}
}

@rustbot labels +A-const-eval +A-patterns +I-crash

Meta

Reproducible on the playground with stable version 1.88.0.

Error output

error: rustc interrupted by SIGSEGV, printing backtrace
Backtrace

/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x399a39f)[0x75dba779a39f]
/lib/x86_64-linux-gnu/libc.so.6(+0x45330)[0x75dba3c33330]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5950f0e)[0x75dba9750f0e]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5933fcb)[0x75dba9733fcb]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x59349db)[0x75dba97349db]

### cycle encountered after 5 frames with period 6
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934bf7)[0x75dba9734bf7]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x592f178)[0x75dba972f178]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934a27)[0x75dba9734a27]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934bf7)[0x75dba9734bf7]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x592f178)[0x75dba972f178]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934a27)[0x75dba9734a27]
### recursed 41 times

/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934bf7)[0x75dba9734bf7]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x592f178)[0x75dba972f178]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934a27)[0x75dba9734a27]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x5934bf7)[0x75dba9734bf7]
/playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/librustc_driver-277627f6f3b9f29c.so(+0x592f178)[0x75dba972f178]

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
error: could not compile `playground` (bin "playground")

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions