rust-lang / rust-lang/rust

Make opsem for all enums consistent, independent of number of variants and `#[non_exhaustive]`

Open
#151,786 6 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-closures A-patterns C-bug I-lang-radar T-lang T-opsem
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

The way we generate MIR currently means that enum opsem distinguished two classes of enums

  • Those with more than 1 variant or a #[non_exhaustive] attribute
  • Those with 1 or 0 variants and no #[non_exhaustive]

For the latter, we sometimes omit reading the discriminant since we "already know the result". Also see https://github.com/rust-lang/rust/pull/150681 where this is point 1.

I think we should treat all enums consistently. This example should be considered UB. In particular, I think #[non_exhaustive] should not affect the opsem.

This change was separated out of https://github.com/rust-lang/rust/pull/150681 at the request of @traviscross, so that it can be discussed separately. So, let's discuss. :) @scottmcm and @nikomatsakis already expressed agreement with this next step in that PR.

Cc @meithecatte -- IIRC this had a non-zero crater fallout; where are the results of that again?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked Rust PR #150681, the playground example, and the MIR opsem discussion, including the referenced crater fallout. A complete contribution requires a settled decision on consistent enum discriminant semantics, followed by implementation and validation that the example is treated as UB without special handling for variant count or #[non_exhaustive].

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.