Skip to content

Allow #[derive(StableHash)] for enums with >256 variants - #166233

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Zalathar:stable-hash-enum
Nov 20, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Zalathar:stable-hash-enum

Conversation

@Zalathar

Copy link
Copy Markdown
Member

When modifying #[derive(StableHash)] for #164953, I made the new implementation only support enums with up to 256 variants, because we currently don't derive StableHash for any enums larger than that.

But later I noticed that LangItem currently has 236 variants, and will probably exceed 256 someday. When someone does add the 257th variant, it would be very confusing for the derive to suddenly stop working. So this PR adds support for enums with 257-65536 variants, by hashing a u16 discriminant instead of a u8.

We currently don't derive StableHash for any enums that large, but LangItem
currently has 236 variants so it will probably exceed 256 someday.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2026
@rustbot

rustbot commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

r? @oli-obk

rustbot has assigned @oli-obk.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 19 candidates

@oli-obk

oli-obk commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a241b25 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #165814 (diag: Fix source location for macro diagnostic message)
 - #166091 (Abby: make the fields of `And/Or` private)
 - #166150 (Reflection: refactor Type and TypeKind)
 - #166213 (remove optionally_braced_mac_call)
 - #166233 (Allow `#[derive(StableHash)]` for enums with >256 variants)
 - #166237 (Add crash test for const param ty unchecked)
@rust-bors
rust-bors Bot merged commit 7ffe06b into rust-lang:main Nov 20, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 20, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
Rollup merge of #166233 - Zalathar:stable-hash-enum, r=oli-obk

Allow `#[derive(StableHash)]` for enums with >256 variants

When modifying `#[derive(StableHash)]` for #164953, I made the new implementation only support enums with up to 256 variants, because we currently don't derive StableHash for any enums larger than that.

But later I noticed that LangItem currently has 236 variants, and will probably exceed 256 someday. When someone does add the 257th variant, it would be very confusing for the derive to suddenly stop working. So this PR adds support for enums with 257-65536 variants, by hashing a u16 discriminant instead of a u8.
@Zalathar
Zalathar deleted the stable-hash-enum branch November 20, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants