Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stack overflow in match pattern with '?' #85787

Closed
davidli2010 opened this issue May 28, 2021 · 1 comment
Closed

stack overflow in match pattern with '?' #85787

davidli2010 opened this issue May 28, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@davidli2010
Copy link

I tried this code:

#![allow(dead_code)]

enum Kind {
    A,
    B,
    C,
    D,
    E,
    F,
    G,
}

const DATA_SIZE: usize = 1024 * 280;

struct Data {
    data: [u8; DATA_SIZE],
}

fn data() -> Option<Data> {
    Some(Data {
        data: [0; DATA_SIZE],
    })
}

fn test(kind: Kind) -> Option<Data> {
    match kind {
        Kind::A => Some(data()?),
        Kind::B => Some(data()?),
        Kind::C => Some(data()?),
        Kind::D => Some(data()?),
        Kind::E => Some(data()?),
        Kind::F => Some(data()?),
        Kind::G => Some(data()?),
    }
}

fn main() {
    let _ = test(Kind::A);
    println!("Done!");
}

Also see in playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6dbc4990244a9b4650b089c2c7996b34

I expected to see this happen: print Done!

Instead, this happened: stack overflow

Meta

rustc --version --verbose:

rustc 1.54.0-nightly (1c6868aa2 2021-05-27)
Backtrace

    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/example`

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
[1]    757 abort      cargo run

@davidli2010 davidli2010 added the C-bug Category: This is a bug. label May 28, 2021
@jonas-schievink
Copy link
Contributor

Duplicate of #34283

@jonas-schievink jonas-schievink marked this as a duplicate of #34283 May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants