Skip to content

Commit

Permalink
WorldQuery derive macro now respects visibility (#4125)
Browse files Browse the repository at this point in the history
## Objective

Fixes #4122.

## Solution

Inherit the visibility of the struct being derived for the `xxItem`, `xxFetch`, `xxState` structs.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
  • Loading branch information
ItsDoot and cart committed Apr 13, 2022
1 parent 995f85e commit 16133de
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/bevy_ecs/macros/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mod field_attr_keywords {
pub static WORLD_QUERY_ATTRIBUTE_NAME: &str = "world_query";

pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
let visibility = ast.vis;

let mut fetch_struct_attributes = FetchStructAttributes::default();
for attr in &ast.attrs {
if !attr
Expand Down Expand Up @@ -233,7 +235,8 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
item_struct_name: Ident| {
if is_filter {
quote! {
struct #fetch_struct_name #impl_generics #where_clause {
#[doc(hidden)]
#visibility struct #fetch_struct_name #impl_generics #where_clause {
#(#field_idents: <#field_types as #path::query::WorldQuery>::#fetch_associated_type,)*
#(#ignored_field_idents: #ignored_field_types,)*
}
Expand Down Expand Up @@ -277,12 +280,13 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
} else {
quote! {
#derive_macro_call
struct #item_struct_name #impl_generics #where_clause {
#visibility struct #item_struct_name #impl_generics #where_clause {
#(#(#field_attrs)* #field_visibilities #field_idents: <<#field_types as #path::query::WorldQuery>::#fetch_associated_type as #path::query::Fetch<#world_lifetime, #world_lifetime>>::Item,)*
#(#(#ignored_field_attrs)* #ignored_field_visibilities #ignored_field_idents: #ignored_field_types,)*
}

struct #fetch_struct_name #impl_generics #where_clause {
#[doc(hidden)]
#visibility struct #fetch_struct_name #impl_generics #where_clause {
#(#field_idents: <#field_types as #path::query::WorldQuery>::#fetch_associated_type,)*
#(#ignored_field_idents: #ignored_field_types,)*
}
Expand Down Expand Up @@ -342,7 +346,8 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
);

let state_impl = quote! {
struct #state_struct_name #impl_generics #where_clause {
#[doc(hidden)]
#visibility struct #state_struct_name #impl_generics #where_clause {
#(#field_idents: <#field_types as #path::query::WorldQuery>::State,)*
#(#ignored_field_idents: #ignored_field_types,)*
}
Expand Down

0 comments on commit 16133de

Please sign in to comment.