Skip to content

Commit

Permalink
Fix label macro for types with generics (bevyengine#1498)
Browse files Browse the repository at this point in the history
Fixes bevyengine#1497

Co-authored-by: Carter Anderson <[email protected]>
  • Loading branch information
TheRawMeatball and cart committed Mar 9, 2021
1 parent 8f36354 commit ea9c7d5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/bevy_ecs/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream {
#[proc_macro_derive(SystemLabel)]
pub fn derive_system_label(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);

derive_label(input, Ident::new("SystemLabel", Span::call_site())).into()
}

Expand All @@ -434,8 +435,15 @@ fn derive_label(input: DeriveInput, label_type: Ident) -> TokenStream2 {
let ident = input.ident;
let ecs_path: Path = bevy_ecs_path();

let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let mut where_clause = where_clause.cloned().unwrap_or_else(|| syn::WhereClause {
where_token: Default::default(),
predicates: Default::default(),
});
where_clause.predicates.push(syn::parse2(quote! { Self: Eq + ::std::fmt::Debug + ::std::hash::Hash + Clone + Send + Sync + 'static }).unwrap());

quote! {
impl #ecs_path::schedule::#label_type for #ident {
impl #impl_generics #ecs_path::schedule::#label_type for #ident #ty_generics #where_clause {
fn dyn_clone(&self) -> Box<dyn #ecs_path::schedule::#label_type> {
Box::new(Clone::clone(self))
}
Expand Down

0 comments on commit ea9c7d5

Please sign in to comment.