Skip to content

Commit 376864b

Browse files
committed
render
1 parent a9fbc24 commit 376864b

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

crates/bevy_asset/macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn derive_dependency_visitor_internal(
8080
let field_visitors = field_locals.clone().map(|i| visit_dep(quote!(#i)));
8181
quote!(Self::#ident {#(#field_members: #field_locals,)* ..} => {
8282
#(#field_visitors)*
83-
},)
83+
})
8484
});
8585

8686
any_case_required.then(|| quote!(match self { #(#cases)*, _ => {} }))

crates/bevy_macro_utils/src/shape.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syn::{spanned::Spanned, Data, DataEnum, DataUnion, Error, Fields};
1+
use syn::{Data, DataEnum, DataUnion, Error, Field, Fields, punctuated::Punctuated, spanned::Spanned, token::Comma};
22

33
/// Get the fields of a data structure if that structure is a struct;
44
/// otherwise, return a compile error that points to the site of the macro invocation.
@@ -17,3 +17,12 @@ pub fn get_struct_fields<'a>(data: &'a Data, meta: &str) -> Result<&'a Fields, E
1717
)),
1818
}
1919
}
20+
21+
/// Return an error if `Fields` is not `Fields::Named`
22+
pub fn require_named<'a>(fields: &'a Fields) -> Result<&'a Punctuated<Field, Comma>, Error> {
23+
if let Fields::Named(fields) = fields {
24+
Ok(&fields.named)
25+
} else {
26+
Err(Error::new(fields.span(), "Unnamed fields are not supported here"))
27+
}
28+
}

crates/bevy_render/macros/src/specializer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bevy_macro_utils::{
22
fq_std::{FQDefault, FQResult},
3-
get_struct_fields,
3+
get_struct_fields, require_named,
44
};
55
use proc_macro::TokenStream;
66
use proc_macro2::Span;
@@ -225,8 +225,9 @@ pub fn impl_specializer(input: TokenStream) -> TokenStream {
225225
let ecs_path = crate::bevy_ecs_path();
226226

227227
let ast = parse_macro_input!(input as DeriveInput);
228-
let targets = guard!(get_specialize_targets(&ast, "Specializer"));
228+
let targets = guard!(get_specialize_targets(&ast, "Specializer"));
229229
let fields = guard!(get_struct_fields(&ast.data, "Specializer"));
230+
let fields = guard!(require_named(fields));
230231
let field_info = guard!(get_field_info(fields, &targets));
231232

232233
let key_idents: Vec<Option<Ident>> = field_info

0 commit comments

Comments
 (0)