Skip to content

Rust: a record holding a struct through an auto-property fails to compile (E0277), because the held struct never derives Clone/Debug/PartialEq #353

Open

Description

@matt-edmondson

What's wrong

The #302 fix (PR #315) makes a struct that a record holds derive Clone, Debug, PartialEq along with the record. It only follows fields, though, not auto-properties:

  • The record: it is lowered with Separated(classDecl) (Coder/Languages/RustGenerator.cs:~501). Its own derive check therefore sees the auto-property as a field, and the record derives.
  • The held struct: when it is written, Derives (:~739, loop at :~756) walks the original records from GenerationRoot.
  • Why the walk misses it: UnderivableReason collects held types only from VariableDeclaration and non-associated FieldDeclaration members (:812-818). A bodiless PropertyDeclaration, which Rust emits as a field, is never walked, so the struct behind it is never marked to derive.

Repro

A SourceFile with:

  • struct Inner { int x } (plain struct)
  • a record struct Outer whose only member is new PropertyDeclaration("Value", "Inner")

The output is:

pub struct Inner { pub x: i32 }

#[derive(Clone, Debug, PartialEq)]
pub struct Outer { pub Value: Inner }

rustc rejects it: error[E0277]: the trait bound Inner: Clone is not satisfied (and the same for Debug and PartialEq).

The same document with VariableDeclaration("value", "Inner") in place of the property generates #[derive(...)] on Inner and compiles. Reproduced at HEAD 1173b65.

Suggested fix

Make the record walk in UnderivableReason / Derives see what Rust actually emits. Either walk Separated(record), or add a PropertyDeclaration arm for auto-properties (no getter or setter body) that yields its Type.

Acceptance criteria

Activity

  1. matt-edmondson commented on Oct 29, 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

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions