Skip to content

Possible codegen regression when matching against nested enums #104519

Closed
@anp

Description

@anp

Code

I tried this code (reduced from a much larger test):

fn main() {
    let output = OpenResult::Ok(());
    match output {
        OpenResult::Ok(()) => (),
        _ => unreachable!("this won't be reached"),
    }
    match output {
        OpenResult::Ok(()) => (),
        _ => unreachable!("somehow matching twice is the trick"),
    }
}

enum OpenResult {
    Ok(()),

    // we don't produce either of these variants but both are necessary to trigger the issue
    #[allow(dead_code)]
    Err(()),
    #[allow(dead_code)]
    TransportErr(TransportErr),
}

#[allow(dead_code)] // don't need to produce this to repro
#[repr(i32)]
enum TransportErr {
    UnknownMethod = -2,
}

(playground)

I expected to see this happen: runs with 0 exit code and no output

Instead, this happened:

thread 'main' panicked at 'internal error: entered unreachable code: somehow matching twice is the trick', src/main.rs:9:14

Version it worked on

This code works on stable and beta, and as recently as a3c0a02.

Version with regression

This reproduces with the 2022-11-16 nightly on the playground. cargo-bisect-rustc suggests this was introduced by #102872.

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions