Skip to content

Let a record declare its own equality in C# and Rust - #313

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/project-thread-71fapa-301
Oct 20, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
claude/project-thread-71fapa-301

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Requested by Matt · project thread

Fixes #301.

Before: a record that declared operator == or operator != did not compile in C# or in Rust. C# reported CS0111, because a record already synthesises both operators and the comparison-partner logic added whichever one was missing. Rust reported E0119, because the record derived PartialEq beside the declared impl PartialEq.

After: both targets compile. In C#, a record's declared == or != is written down as inexpressible, since the record supplies both, and no partner is added for it. In Rust, a record that declares == leaves PartialEq out of its derive, so the declared impl is the only one. Records that declare no equality operator keep their current output.

How: CSharpGenerator checks whether an operator is one a record synthesises over its own type (RecordSynthesises) before writing it, and MissingComparisonPartners skips those. RustGenerator drops PartialEq from the derive list when the record declares ==. RecordEqualityTests compiles a record declaring == and one declaring only != with dotnet build and rustc, and pins the unchanged output for a plain record.


Generated by Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014YYYK5TCGFXNo5ofZckGoo
@matt-edmondson matt-edmondson self-assigned this Oct 20, 2026
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit bc35c1a into main Oct 20, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the claude/project-thread-71fapa-301 branch October 20, 2026 11:48
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.

A record that declares operator == doesn't compile in C# (CS0111) or Rust (E0119) because the record already supplies equality

2 participants