bevyengine/bevy · error · syn::Error
The `key` attribute is not supported for structs with named
Error message
The `key` attribute is not supported for structs with named fields
What it means
Compile error from derive_settings_group: the input is a struct with named fields (where each field already defines its own sub-key) but an explicit `key = "..."` override attribute was also supplied. The key attribute only applies to tuple/unit structs, so this guard rejects the combination.
Source
Thrown at crates/bevy_ecs/macros/src/lib.rs:707
} else if meta.path.is_ident("file") {
let value = meta.value()?;
let s: syn::LitStr = value.parse()?;
override_file = Some(s.value());
Ok(())
} else {
Err(meta.error("unsupported attribute"))
}
})
.ok()
});
(override_group_name, override_key_name, override_file)
};
let key_name = match &input.data {
Data::Struct(data) => match data.fields {
Fields::Named(_) if override_key_name.is_some() => {
return syn::Error::new(
Span::call_site(),
"The `key` attribute is not supported for structs with named fields",
)
.into_compile_error()
.into();
}
Fields::Named(_) => None,
Fields::Unnamed(_) | Fields::Unit => {
override_key_name.or_else(|| Some(pascal_to_snake_case(&name.to_string())))
}
},
Data::Enum(_) => override_key_name.or(Some(pascal_to_snake_case(&name.to_string()))),
Data::Union(_) => {
return syn::Error::new(
Span::call_site(),
"SettingsGroup cannot be derived for unions",
)
.into_compile_error()View on GitHub (pinned to 396ca72708)
Solutions
- Remove the #[key = "...")] attribute and let named fields supply their own keys
- Convert the struct to a tuple or unit struct if a single key override is needed
- Apply key overrides at the field/group level where supported
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_ecs/macros/src/lib.rs:707 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/189f83f216dfb139.
Report an issue: GitHub.