rust-lang / rust-lang/rfcs

consider changing size of empty enum to usize::MAX

Open
#1,076 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-compiler T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

spawned off of https://github.com/rust-lang/rust/issues/24590

Empty enums such as:

enum Empty { }

are a hazard in a number of ways; in particular, odd people like myself keep wanting to investigate what happens if you unsafely inject a value into Empty, e.g. via mem::transmute (or by derefing an unsafe pointer *const Empty, etc).

The resulting code you get when doing a match on such a value is pretty much guaranteed to be undefined behavior. The project developers have stated that the memory layout of an empty enum (in fact, of all non C-like enums) is undefined, and thus undefined behavior is justifiable here.

Still, it seems to easy to expose this case, and it seems like it would be really easy to prevent it, e.g. by changing the representation size of an empty enum to something semi-absurd. Like usize::MAX.

Contributor guide

No contributing guide indexed for this repository

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 issue #24590 and the discussion here about empty-enum layout and unsafe values. Determine whether changing the representation size to usize::MAX is technically and semantically appropriate, and document the design decision and its consequences; the issue names no implementation files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
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.