What's wrong
StandardLanguageGenerator.GetUnaryOperatorSpelling (Coder/Languages/StandardLanguageGenerator.cs:747) falls back to the C-family symbols in OperatorSymbols (Coder/Ast/OperatorSymbols.cs:127-129): Plus => "+" and BitwiseNot => "~". Go and Python override the method where their spelling differs (GoGenerator.cs:258 writes ^ for bitwise not). RustGenerator does not override it.
Repro
new RustGenerator().Generate(new UnaryExpression(UnaryOperator.Plus, new VariableReference("x"))); // "(+x)"
new RustGenerator().Generate(new UnaryExpression(UnaryOperator.BitwiseNot, new VariableReference("x"))); // "(~x)"
rustc rejects both:
let a = (+x); fails with error: expected expression, found '+'
let b = (~x); fails with error: '~' cannot be used as a unary operator
Coder.Test/Languages/UnaryOperandSignTests.cs includes [DataRow(UnaryOperator.Plus, -1, "(+-1)")] for Rust. That test locks in the invalid output.
Why it matters
Any AST that uses bitwise complement, such as mask manipulation like flags & ~MASK, or an explicit unary plus, produces Rust that does not compile.
Suggested fix
Override GetUnaryOperatorSpelling in RustGenerator:
BitwiseNot => "!". Rust's ! is bitwise not on integers.
Plus => "". Unary plus is the identity, so write just the operand, and keep the parentheses if needed for precedence.
Correct the Rust expectation in UnaryOperandSignTests.
Acceptance: Rust output for both operators compiles with rustc, and the tests assert (!x) and (x).
What's wrong
StandardLanguageGenerator.GetUnaryOperatorSpelling(Coder/Languages/StandardLanguageGenerator.cs:747) falls back to the C-family symbols inOperatorSymbols(Coder/Ast/OperatorSymbols.cs:127-129):Plus => "+"andBitwiseNot => "~". Go and Python override the method where their spelling differs (GoGenerator.cs:258writes^for bitwise not).RustGeneratordoes not override it.Repro
rustc rejects both:
let a = (+x);fails witherror: expected expression, found '+'let b = (~x);fails witherror: '~' cannot be used as a unary operatorCoder.Test/Languages/UnaryOperandSignTests.csincludes[DataRow(UnaryOperator.Plus, -1, "(+-1)")]for Rust. That test locks in the invalid output.Why it matters
Any AST that uses bitwise complement, such as mask manipulation like
flags & ~MASK, or an explicit unary plus, produces Rust that does not compile.Suggested fix
Override
GetUnaryOperatorSpellinginRustGenerator:BitwiseNot => "!". Rust's!is bitwise not on integers.Plus => "". Unary plus is the identity, so write just the operand, and keep the parentheses if needed for precedence.Correct the Rust expectation in
UnaryOperandSignTests.Acceptance: Rust output for both operators compiles with rustc, and the tests assert
(!x)and(x).