Spell bitwise not as ! and drop unary plus in Rust output [patch] - #129
Merged
Merged
Conversation
RustGenerator fell back to the C-family unary spellings, so it wrote (~x) and (+x). Rust has neither operator, and rustc rejects both. It now overrides GetUnaryOperatorSpelling: BitwiseNot is "!", which is Rust's bitwise complement on integers, and Plus writes the operand alone, still parenthesised. UnaryOperandSignTests asserted the invalid "(+-1)" for Rust. It now leaves Rust out of the unary-plus row, and RustGeneratorTests covers Rust's spelling. A rustc compile test covers both operators. Fixes #97 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015i2yeKwKRWtHhdc6NPySjW
|
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 #97
What was wrong
RustGeneratordid not overrideGetUnaryOperatorSpelling, so it used the C-family spellings and wrote(~x)and(+x). Rust has neither operator, and rustc rejects both.Change
RustGenerator.GetUnaryOperatorSpelling:BitwiseNot→!, which is Rust's bitwise complement on integers.Plus→ the operand alone. The shared emitter still wraps it in parentheses, so precedence is unchanged:(x),(-1).UnaryOperandSignTests.AnOperandThatCannotFuseIsWrittenBareasserted the invalid(+-1)for Rust. That row now leaves Rust out, and Rust's spelling is asserted inRustGeneratorTestsinstead.Tests
RustGeneratorTests.UnaryOperators_AreSpelledAsRustWritesThemchecks(!x)for bitwise not,(x)for plus, and that logical not and negate are unchanged.UnaryPlusOnANegativeLiteral_IsTheLiteralchecks(-1).RustGeneratedSourceCompilesTests.UnaryOperatorsRustSpellsDifferently_Compilecompiles functions that use both operators with rustc.RustGenerator.csand re-ran: all four new tests fail, including rustc rejecting the output. With the fix they pass.Coder.Testsuite on Linux, with rustc on the path: 987 passed, 0 failed.🤖 Generated with Claude Code
https://claude.ai/code/session_015i2yeKwKRWtHhdc6NPySjW
Generated by Claude Code