Repository navigation
Allow #[derive(StableHash)] for enums with >256 variants - #166233
Merged
Merged
Conversation
We currently don't derive StableHash for any enums that large, but LangItem currently has 236 variants so it will probably exceed 256 someday.
Collaborator
|
r? @oli-obk rustbot has assigned @oli-obk. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
|
@bors r+ rollup |
Contributor
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 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.