{"record":{"id":"37973eabaf55eca6","repo":"bevyengine/bevy","slug":"derive-fromworld-does-not-support-unions","errorCode":null,"errorMessage":"#[derive(FromWorld)]` does not support unions","messagePattern":"#\\[derive\\(FromWorld\\)\\]` does not support unions","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"crates/bevy_ecs/macros/src/lib.rs","lineNumber":912,"sourceCode":"            match data.variants.iter().find(|variant| {\n                variant\n                    .attrs\n                    .iter()\n                    .any(|attr| attr.path().is_ident(\"from_world\"))\n            }) {\n                Some(variant) => (&variant.fields, Some(&variant.ident)),\n                None => {\n                    return syn::Error::new(\n                        Span::call_site(),\n                        \"No variant found with the `#[from_world]` attribute\",\n                    )\n                    .into_compile_error()\n                    .into();\n                }\n            }\n        }\n        Data::Union(_) => {\n            return syn::Error::new(\n                Span::call_site(),\n                \"#[derive(FromWorld)]` does not support unions\",\n            )\n            .into_compile_error()\n            .into();\n        }\n    };\n\n    let field_init_expr = quote!(#bevy_ecs_path::world::FromWorld::from_world(world));\n    let members = fields.members();\n\n    let field_initializers = match variant_ident {\n        Some(variant_ident) => quote!( Self::#variant_ident {\n            #(#members: #field_init_expr),*\n        }),\n        None => quote!( Self {\n            #(#members: #field_init_expr),*\n        }),","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_ecs/macros/src/lib.rs#L894-L930","documentation":"Compile error from derive_from_world: the DeriveInput's data is a DataUnion, which the FromWorld derive cannot generate an implementation for. This branch of the struct/enum/union match raises the unsupported-shape sentinel.","triggerScenarios":"Thrown at crates/bevy_ecs/macros/src/lib.rs:912 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the union with a struct or enum","If per-field construction from World is needed, implement FromWorld manually for a struct"],"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-14T00:17:10.932Z"}