Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
  • Loading branch information
mvlabat and MinerSebas committed Feb 13, 2022
1 parent 27b1155 commit 96f6043
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/bevy_ecs/macros/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
attr.parse_args_with(|input: ParseStream| {
let meta = input.parse_terminated::<syn::Meta, syn::token::Comma>(syn::Meta::parse)?;
for meta in meta {
let ident = meta.path().get_ident();
if ident.map_or(false, |ident| ident == MUTABLE_ATTRIBUTE_NAME) {
let ident = meta.path().get_ident().unwrap_or_else(|| {
panic!(
"Unrecognized attribute: `{}`",
meta.path().to_token_stream()
)
});
if ident == MUTABLE_ATTRIBUTE_NAME {
if let syn::Meta::Path(_) = meta {
fetch_struct_attributes.is_mutable = true;
} else {
Expand All @@ -51,7 +56,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
MUTABLE_ATTRIBUTE_NAME
);
}
} else if ident.map_or(false, |ident| ident == DERIVE_ATTRIBUTE_NAME) {
} else if ident == DERIVE_ATTRIBUTE_NAME {
if let syn::Meta::List(meta_list) = meta {
fetch_struct_attributes
.derive_args
Expand All @@ -62,7 +67,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
DERIVE_ATTRIBUTE_NAME
);
}
} else if ident.map_or(false, |ident| ident == FILTER_ATTRIBUTE_NAME) {
} else if ident == FILTER_ATTRIBUTE_NAME {
if let syn::Meta::Path(_) = meta {
fetch_struct_attributes.is_filter = true;
} else {
Expand Down Expand Up @@ -180,6 +185,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
}
}

// We expect that only regular query declarations have a lifetime.
if fetch_struct_attributes.is_filter {
if has_world_lifetime {
panic!("Expected a struct without a lifetime");
Expand Down Expand Up @@ -479,12 +485,12 @@ fn read_world_query_field_info(
let attrs = field
.attrs
.iter()
.cloned()
.filter(|attr| {
attr.path
.get_ident()
.map_or(true, |ident| ident != WORLD_QUERY_ATTRIBUTE_NAME)
})
.cloned()
.collect();

let field_type = field.ty.clone();
Expand Down

0 comments on commit 96f6043

Please sign in to comment.