Repository navigation
Derive Clone, Copy, Debug, PartialEq, Eq and Hash on Rust enums [patch] - #263
Merged
Merged
Conversation
A generated Rust enum derived nothing, so comparing two of its values failed with E0369, a record holding one failed with E0277, and reading one out of &self failed with E0507. A fieldless enum can always derive these, unlike a struct whose fields might not implement them. Fixes #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175VbFC9TAs3FcivXVHTFum
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175VbFC9TAs3FcivXVHTFum
Resolve RustGenerator.WriteEnum: main hoisted the enum name into a local and added the discriminant cast; keep that and emit this branch's derive line before the enum header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MBvWhCTdazHGpnqRd3FD7s
|
This was referenced Oct 19, 2026
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.



Fixes #255
Before:
RustGenerator.GenerateEnumDeclarationwrote no#[derive]on an enum. Comparing two values failed with E0369, a record holding one failed with E0277, and reading one out of&selffailed with E0507.After: every generated enum gets
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]on the line directly aboveenum, after the preamble and#[repr]. Plain structs derive nothing because a field might not implement these traits. A fieldless enum has no fields, so that reason doesn't apply.Tests:
RustGeneratedSourceCompilesTests.EnumValuesCompareCopyAndSitInARecord_Compileruns rustc on the three scenarios from the issue. With the generator change reverted it fails with E0369, E0277 and E0507. With the change it passes.RustGeneratorTestsenum assertions to expect the derive line.Generated by Claude Code