{"record":{"id":"2f448e1c9f900062","repo":"bevyengine/bevy","slug":"derive-derive-expected-named-structs-with-a-sing","errorCode":null,"errorMessage":"{derive} derive expected named structs with a single field or with a field annotated with #[relationship].","messagePattern":"(.+?) derive expected named structs with a single field or with a field annotated with #\\[relationship\\]\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/macro_logic/src/component.rs","lineNumber":806,"sourceCode":"        })\n    }\n}\n\n/// Returns the field with the `#[relationship]` attribute, the only field if unnamed,\n/// or the only field in a [`Fields::Named`] with one field, otherwise `Err`.\npub(crate) fn relationship_field<'a>(\n    fields: &'a Fields,\n    derive: &'static str,\n    span: Span,\n) -> Result<&'a Field> {\n    match fields {\n        Fields::Named(fields) if fields.named.len() == 1 => Ok(fields.named.first().unwrap()),\n        Fields::Named(fields) => fields.named.iter().find(|field| {\n            field\n                .attrs\n                .iter()\n                .any(|attr| attr.path().is_ident(RELATIONSHIP))\n        }).ok_or(syn::Error::new(\n            span,\n            format!(\"{derive} derive expected named structs with a single field or with a field annotated with #[relationship].\")\n        )),\n        Fields::Unnamed(fields) if fields.unnamed.len() == 1 => Ok(fields.unnamed.first().unwrap()),\n        Fields::Unnamed(fields) => fields.unnamed.iter().find(|field| {\n                field\n                    .attrs\n                    .iter()\n                    .any(|attr| attr.path().is_ident(RELATIONSHIP))\n            })\n            .ok_or(syn::Error::new(\n                span,\n                format!(\"{derive} derive expected unnamed structs with one field or with a field annotated with #[relationship].\"),\n            )),\n        Fields::Unit => Err(syn::Error::new(\n            span,\n            format!(\"{derive} derive expected named or unnamed struct, found unit struct.\"),\n        )),","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/macro_logic/src/component.rs#L788-L824","documentation":"Compile error from relationship_field: the derive was applied to a named struct with multiple fields, and none of them carries the #[relationship] attribute, so the helper cannot determine which field stores the related Entity. The span passed in (usually the struct or derive span) anchors this generic validation guard.","triggerScenarios":"Thrown at crates/bevy_ecs/macro_logic/src/component.rs:806 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Annotate exactly one field with #[relationship], e.g. #[relationship] pub target: Entity","Reduce the named struct to a single field so it is used unambiguously","Use a tuple struct with one field: struct ChildOf(Entity);"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}