Skip to content

Rust: a record with a field of a plain struct type doesn't compile (E0277/E0369) because only the record derives Clone/Debug/PartialEq #302

Closed

Description

@matt-edmondson

What's wrong

RustGenerator deliberately derives nothing on plain structs; the remarks around Coder/Languages/RustGenerator.cs L413-416 explain why. It does, however, write #[derive(Clone, Debug, PartialEq)] on every IsRecord type (around L591-595). As soon as a record has a field whose type is a non-record struct declared in the same tree, the record's derive can't be satisfied.

Reproduction

A plain struct Point { int x } plus a record struct Line { Point a } generates:

pub struct Point { pub x: i32, }

#[derive(Clone, Debug, PartialEq)]
pub struct Line { pub a: Point, }

rustc rejects it:

  • error[E0277]: the trait bound 'Point: Clone' is not satisfied
  • error[E0277]: 'Point' doesn't implement 'Debug'
  • error[E0369]: binary operation '==' cannot be applied to type 'Point'

The C# output for the same AST (record struct Line { public Point a; }) compiles.

#255 and open PR #263 fix this same failure for enum fields only. Struct fields aren't covered.

Suggested fix

When a record's field type names a struct declared in the generation root, give that struct the same derive, transitively. Field types include type arguments and array element types. When the field type isn't declared in the tree, or is an interface or trait, write the inexpressible note instead of a derive that can't compile. Sharing the "which types need the derive" walk with the #255 enum fix would keep the two consistent.

Acceptance criteria

  • RustGeneratedSourceCompilesTests has a case for a record holding a plain struct, and one for a record holding another record.
  • A plain struct that no record uses still gets no derive.

Activity

  1. added
    bug
    on Oct 19, 2026
  2. matt-edmondson commented on Oct 19, 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