Skip to content

Commit 2adff99

Browse files
committed
Add attribute macro to enable the warning for missed events
1 parent b8010d7 commit 2adff99

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

crates/bevy_ecs/macros/src/component.rs

-18
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,6 @@ use proc_macro2::{Span, TokenStream as TokenStream2};
44
use quote::{quote, ToTokens};
55
use syn::{parse_macro_input, parse_quote, DeriveInput, Error, Ident, Path, Result};
66

7-
pub fn derive_event(input: TokenStream) -> TokenStream {
8-
let mut ast = parse_macro_input!(input as DeriveInput);
9-
let bevy_ecs_path: Path = crate::bevy_ecs_path();
10-
11-
ast.generics
12-
.make_where_clause()
13-
.predicates
14-
.push(parse_quote! { Self: Send + Sync + 'static });
15-
16-
let struct_name = &ast.ident;
17-
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
18-
19-
TokenStream::from(quote! {
20-
impl #impl_generics #bevy_ecs_path::event::Event for #struct_name #type_generics #where_clause {
21-
}
22-
})
23-
}
24-
257
pub fn derive_resource(input: TokenStream) -> TokenStream {
268
let mut ast = parse_macro_input!(input as DeriveInput);
279
let bevy_ecs_path: Path = crate::bevy_ecs_path();

crates/bevy_ecs/macros/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate proc_macro;
22

33
mod component;
4+
mod event;
45
mod fetch;
56
mod set;
67
mod states;
@@ -482,9 +483,9 @@ pub(crate) fn bevy_ecs_path() -> syn::Path {
482483
BevyManifest::default().get_path("bevy_ecs")
483484
}
484485

485-
#[proc_macro_derive(Event)]
486+
#[proc_macro_derive(Event, attributes(event))]
486487
pub fn derive_event(input: TokenStream) -> TokenStream {
487-
component::derive_event(input)
488+
event::derive_event(input)
488489
}
489490

490491
#[proc_macro_derive(Resource)]

0 commit comments

Comments
 (0)