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: a specialisation writes its nested types twice, the second copy inside impl Trait for Type, so the output fails to compile (E0449) #370
RustGenerator.GenerateClassDeclaration first writes every nested type (ClassDeclaration, EnumDeclaration, UsingAlias) beside the type, at Coder/Languages/RustGenerator.cs:505-509. For a specialisation it then calls GenerateSpecialisation (:610-623), which runs WriteMembers(classDecl.Members, code) over all members. WriteMembers (StandardLanguageGenerator.cs:1006) does no filtering, so every nested type is written a second time, this time inside impl Trait for Type { … }.
A UsingAlias inside a specialisation is the C++ template<> struct Describe<RigidBody> { using Field = float; }; idiom. It comes out as a module-level pub type Field = f32; and then a second pub type Field = f32; inside the impl. rustc rejects the second with E0449 "visibility qualifiers are not permitted here". Two specialisations that alias the same name also collide at module scope (E0428).
A nested struct is written a second time inside the impl, which rustc rejects with "struct is not supported in traits or impls".
I reproduced both compiler errors with rustc on hand-written output of the same shape.
Repro
vardescribe=newClassDeclaration("Describe"){SpecialisationArguments={newTypeReference("RigidBody")}};describe.Members.Add(newUsingAlias("Field","float"));newRustGenerator().Generate(describe);// pub type Field = f32;// impl Describe for RigidBody {// pub type Field = f32; // E0449// }
Suggested fix / acceptance criteria
Make GenerateSpecialisation skip the members that IsTypeDeclaration already hoisted, for example with WriteMembers(classDecl.Members.Where(m => !IsTypeDeclaration(m)), code). The alternative is to write a UsingAlias inside a specialisation once, as an associated type (type Field = f32;, with no pub), and not hoist it. The first option is the smaller change.
Add a case to RustGeneratedSourceCompilesTests that compiles a specialisation holding a UsingAlias, and another that compiles a specialisation holding a nested class.
Priority: Medium. A Rust specialisation that holds a UsingAlias or a nested class produces output that does not compile (E0449, E0428, or "struct is not supported in traits or impls"). It fails loudly rather than silently, and it only affects specialisations with nested types. The suggested fix is a one-line filter in GenerateSpecialisation.
Activity
matt-edmondson commentedon Oct 30, 2026
Triage
UsingAliasor a nested class produces output that does not compile (E0449, E0428, or "struct is not supported in traits or impls"). It fails loudly rather than silently, and it only affects specialisations with nested types. The suggested fix is a one-line filter inGenerateSpecialisation.RustGenerator.GenerateClassDeclaration/GenerateSpecialisation(Coder/Languages/RustGenerator.cs:505-509,:610-623).GenerateSpecialisationwrites every member insideimpl Trait for Type, which also misplaces aCompileTimeAssertionthere. A single!IsTypeDeclaration(m)-style filter, widened to cover assertions, could fix both, so it is worth landing them together. Rust: after a failed generation inside a trait or specialisation, later output on the same generator losespuband emits bodilessfn f();#357 also involves Rust specialisations, but it covers state left behind after a failed generation, which is different.GenerateSpecialisation(Append a String by reference in Rust and note a string += in C [patch] #369, Export a C or C++ header document as .h or .hpp [minor] #368, Call keyword-named functions and methods by their escaped names [patch] #366, Escape keyword-named enum members in C++ and Rust [patch] #365, Restore the Rust trait and Go interface flags when a member throws [patch] #360, Wrap Python's ~ on unsigned and << on fixed-width integers to the C family's width [patch] #358 and Say a C# local's type when it has no initialiser to infer from [patch] #356 cover other areas).Generated by Claude Code