Skip to content

Nested recursive enum with ManuallyDrop causes thread 'rustc' to overflow its stack #135093

Closed
@w-utter

Description

@w-utter

There seemed to be an issue with the type Composition<Conditional> adding drop-check rules, so I added ManuallyDrop to get the program to compile. I also added the unpin impl as there was also an error regarding its implementation.

I tried this code:

use std::mem::ManuallyDrop;

pub enum Composition<T> {
    Conditional(ManuallyDrop<Conditional<T>>),
    Item(T),
}

impl <T> Unpin for Composition<T> {}

#[derive(Default)]
pub struct Conditional<T> {
    _condition: Vec<Composition<Condition<T>>>,
    _warrant: Vec<Composition<T>>,
}

pub enum Condition<T> {
    T(T),
}

fn main() {
    let _ = Conditional::<()>::default();
}

I expected wither for the program to run, or for the compiler to give the a similar error to when ManuallyDrop is removed: "overflow while adding drop-check rules for Vec<Composition<T>>"

Instead, the rustc thread overflowed its stack.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (3f43b1a63 2025-01-03)
binary: rustc
commit-hash: 3f43b1a636738f41c48df073c5bcb97a97bf8459
commit-date: 2025-01-03
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.6
Backtrace

   Compiling overflow-issue v0.1.0 (/Users/wutter/dev/overflow-issue)

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
error: could not compile `overflow-issue` (bin "overflow-issue")

Caused by:
  process didn't exit successfully: `/Users/wutter/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/rustc --crate-name overflow_issue --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=80 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=2a6ba930726f09c1 -C extra-filename=-15d023de81aec2c9 --out-dir /Users/wutter/dev/overflow-issue/target/debug/deps -C incremental=/Users/wutter/dev/overflow-issue/target/debug/incremental -L dependency=/Users/wutter/dev/overflow-issue/target/debug/deps` (signal: 6, SIGABRT: process abort signal)```

Metadata

Metadata

Assignees

Labels

A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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