bevyengine/bevy · error · syn::Error
No variant found with the `#[from_world]` attribute
Error message
No variant found with the `#[from_world]` attribute
What it means
Compile error from derive_from_world when the input is an enum: the search over variants for one carrying the #[from_world] attribute found none, so no variant was selected for the generated FromWorld impl. The derive requires exactly one designated variant on enums.
Source
Thrown at crates/bevy_ecs/macros/src/lib.rs:902
#[proc_macro_derive(FromWorld, attributes(from_world))]
pub fn derive_from_world(input: TokenStream) -> TokenStream {
let bevy_ecs_path = bevy_ecs_path();
let ast = parse_macro_input!(input as DeriveInput);
let name = ast.ident;
let (impl_generics, ty_generics, where_clauses) = ast.generics.split_for_impl();
let (fields, variant_ident) = match &ast.data {
Data::Struct(data) => (&data.fields, None),
Data::Enum(data) => {
match data.variants.iter().find(|variant| {
variant
.attrs
.iter()
.any(|attr| attr.path().is_ident("from_world"))
}) {
Some(variant) => (&variant.fields, Some(&variant.ident)),
None => {
return syn::Error::new(
Span::call_site(),
"No variant found with the `#[from_world]` attribute",
)
.into_compile_error()
.into();
}
}
}
Data::Union(_) => {
return syn::Error::new(
Span::call_site(),
"#[derive(FromWorld)]` does not support unions",
)
.into_compile_error()
.into();
}
};
View on GitHub (pinned to 396ca72708)
Solutions
- Mark exactly one enum variant with #[from_world]: #[from_world] Variant(Type,)
- Use a struct instead, where the whole type gets the derived FromWorld impl
- Ensure the attribute spelling matches `from_world` exactly
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/macros/src/lib.rs:902 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/4d4176d4c3d48504.
Report an issue: GitHub.