You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rust generator turns static/const fields inside a type into per-instance struct fields and silently drops their value #81
Inside a type, the Rust generator writes every FieldDeclaration through WriteStructMember and ignores IsStatic, IsConstant and InitialValue. This happens in two places in Coder/Languages/RustGenerator.cs:
the struct member loop (~545-548)
the insideType > 0 branch of the field generator (~1035-1041)
Only file-scope and trait items take the path that writes a const or static (~1063-1064).
Failure scenario
Input: class Cfg with FieldDeclaration("Limit", "int") { IsStatic = true, IsConstant = true, InitialValue = 8 }.
Target
Output
C++
static constexpr int Limit = 8;
Go
const CfgLimit int = 8
C
writes a note that it can't express this
Rust
pub Limit: i32, inside struct Cfg
In the Rust output the value 8 is gone. The constant has become a per-instance field that every constructor now has to supply. No note is written either, which is the "quietly loses it" outcome CLAUDE.md says the generators avoid.
Suggested fix
Keep static and constant fields out of the struct body.
Emit constant fields as associated constants in the type's inherent impl block: pub const LIMIT: i32 = 8;.
A non-constant static has no associated-item form in Rust. Emit a note, or a module-level static with a documented name mangling, rather than dropping it silently.
Add a test covering a static const field in a Rust struct.
Priority: Medium. Rust output loses a constant's value without any note, which breaks the generators' "never silently drop" rule. It is limited to static or const fields declared inside a type.
Area / suggested owner: Rust generator (Coder/Languages/RustGenerator.cs)
Activity
matt-edmondson commentedon Sep 26, 2026
Triage
Coder/Languages/RustGenerator.cs)static int count = 0;), which doesn't compile #80 (C++ static fields); both come from static-field handling inside types, so they could be fixed together. No open PR references this issue.Generated by Claude Code