EntityEvent derive: Fix silent error (#19894)
# Objective The `EntityEvent` derive macro only parsed the first `entity_event` attr, resulting in the following event having auto propagation silently turned off: ```rust #[derive(Event, EntityEvent)] #[entity_event(traversal = &'static ChildOf)] #[entity_event(auto_propagate)] struct MyEvent; ``` This should either fail to compile or be parsed correctly. ## Solution Parse all `entity_event`. ## Testing Cargo expand the snippet above. I haven't added an extra test for this.
This commit is contained in:
parent
bdd3ef71b8
commit
c6ba3d31cf
@ -40,19 +40,26 @@ pub fn derive_entity_event(input: TokenStream) -> TokenStream {
|
|||||||
let mut traversal: Type = parse_quote!(());
|
let mut traversal: Type = parse_quote!(());
|
||||||
let bevy_ecs_path: Path = crate::bevy_ecs_path();
|
let bevy_ecs_path: Path = crate::bevy_ecs_path();
|
||||||
|
|
||||||
|
let mut processed_attrs = Vec::new();
|
||||||
|
|
||||||
ast.generics
|
ast.generics
|
||||||
.make_where_clause()
|
.make_where_clause()
|
||||||
.predicates
|
.predicates
|
||||||
.push(parse_quote! { Self: Send + Sync + 'static });
|
.push(parse_quote! { Self: Send + Sync + 'static });
|
||||||
|
|
||||||
if let Some(attr) = ast.attrs.iter().find(|attr| attr.path().is_ident(EVENT)) {
|
for attr in ast.attrs.iter().filter(|attr| attr.path().is_ident(EVENT)) {
|
||||||
if let Err(e) = attr.parse_nested_meta(|meta| match meta.path.get_ident() {
|
if let Err(e) = attr.parse_nested_meta(|meta| match meta.path.get_ident() {
|
||||||
|
Some(ident) if processed_attrs.iter().any(|i| ident == i) => {
|
||||||
|
Err(meta.error(format!("duplicate attribute: {ident}")))
|
||||||
|
}
|
||||||
Some(ident) if ident == AUTO_PROPAGATE => {
|
Some(ident) if ident == AUTO_PROPAGATE => {
|
||||||
auto_propagate = true;
|
auto_propagate = true;
|
||||||
|
processed_attrs.push(AUTO_PROPAGATE);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Some(ident) if ident == TRAVERSAL => {
|
Some(ident) if ident == TRAVERSAL => {
|
||||||
traversal = meta.value()?.parse()?;
|
traversal = meta.value()?.parse()?;
|
||||||
|
processed_attrs.push(TRAVERSAL);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Some(ident) => Err(meta.error(format!("unsupported attribute: {ident}"))),
|
Some(ident) => Err(meta.error(format!("unsupported attribute: {ident}"))),
|
||||||
|
Loading…
Reference in New Issue
Block a user