Skip to content

Commit c6ba3d3

Browse files
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.
1 parent bdd3ef7 commit c6ba3d3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

crates/bevy_ecs/macros/src/component.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,26 @@ pub fn derive_entity_event(input: TokenStream) -> TokenStream {
4040
let mut traversal: Type = parse_quote!(());
4141
let bevy_ecs_path: Path = crate::bevy_ecs_path();
4242

43+
let mut processed_attrs = Vec::new();
44+
4345
ast.generics
4446
.make_where_clause()
4547
.predicates
4648
.push(parse_quote! { Self: Send + Sync + 'static });
4749

48-
if let Some(attr) = ast.attrs.iter().find(|attr| attr.path().is_ident(EVENT)) {
50+
for attr in ast.attrs.iter().filter(|attr| attr.path().is_ident(EVENT)) {
4951
if let Err(e) = attr.parse_nested_meta(|meta| match meta.path.get_ident() {
52+
Some(ident) if processed_attrs.iter().any(|i| ident == i) => {
53+
Err(meta.error(format!("duplicate attribute: {ident}")))
54+
}
5055
Some(ident) if ident == AUTO_PROPAGATE => {
5156
auto_propagate = true;
57+
processed_attrs.push(AUTO_PROPAGATE);
5258
Ok(())
5359
}
5460
Some(ident) if ident == TRAVERSAL => {
5561
traversal = meta.value()?.parse()?;
62+
processed_attrs.push(TRAVERSAL);
5663
Ok(())
5764
}
5865
Some(ident) => Err(meta.error(format!("unsupported attribute: {ident}"))),

0 commit comments

Comments
 (0)