Skip to content

Rust generator turns static/const fields inside a type into per-instance struct fields and silently drops their value #81

Closed

Description

@matt-edmondson

What's wrong

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.

Activity

  1. added
    bug
    on Sep 26, 2026
  2. matt-edmondson commented on Sep 26, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions