Skip to content

Double the braces in a Rust compile-time assertion message [patch] - #194

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/166-rust-assert-braces
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/166-rust-assert-braces

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #166

What changed

RustGenerator.GenerateCompileTimeAssertion passed CompileTimeAssertion.Message to assert! as its second argument, and only escaped it. assert! reads that argument as a format string, so braces in the message were treated as format syntax:

  • "size {N} fits" failed with E0425: cannot find value 'N'.
  • "brace {} here" failed with a missing positional argument.

The generator now doubles { and } after escaping. The message reaches the compiler's error text unchanged. C, C++ and Go don't use a format string here, so they are unchanged.

Tests

  • RustGeneratorTests.CompileTimeAssertion_DoublesBracesInTheMessage: checks that size {N} fits, brace {} here is written as size {{N}} fits, brace {{}} here.
  • RustGeneratedSourceCompilesTests: the exemplar now has a second assertion with that message, and the test compiles it with rustc.

With the generator change reverted, both tests fail, and rustc reports E0425 and the missing-argument error. With the change, the full suite passes (1101/1101).

🤖 Generated with Claude Code

https://claude.ai/code/session_01X8BPy6trRZiUxiwJcbUGzR


Generated by Claude Code

assert! reads its message as a format string, so a message such as
"size {N} fits" was parsed as a placeholder naming N and the output
failed with E0425, and "brace {} here" failed with a missing argument.
The Rust generator now doubles { and } after escaping the message, so
the text reaches the compiler's error unchanged.

Fixes #166

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X8BPy6trRZiUxiwJcbUGzR
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 30dcc87 into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/166-rust-assert-braces branch October 9, 2026 07:55
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: a compile-time assertion message containing { or } fails to compile because it is passed to assert! as a format string

2 participants