Skip to content

Derive Clone, Copy, Debug, PartialEq, Eq and Hash on Rust enums [patch] - #263

Merged
matt-edmondson merged 3 commits into
mainfrom
fix/255-rust-enum-derives
Oct 20, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
fix/255-rust-enum-derives

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #255

Before: RustGenerator.GenerateEnumDeclaration wrote no #[derive] on an enum. Comparing two values failed with E0369, a record holding one failed with E0277, and reading one out of &self failed with E0507.

After: every generated enum gets #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] on the line directly above enum, 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:

  • New RustGeneratedSourceCompilesTests.EnumValuesCompareCopyAndSitInARecord_Compile runs 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.
  • Updated the two RustGeneratorTests enum assertions to expect the derive line.
  • Full suite: 1284 passed, 0 failed.

Generated by Claude Code

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
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust: generated enums derive nothing, so comparing two enum values fails (E0369) and a record holding an enum field fails (E0277)

2 participants