Fix unused variable warning for simple AssetV2 derives (#9961)
# Objective Fix #9960 ## Solution Make the `visit` parameter `_visit` if there are no dependencies. New `cargo expand` output: ```rust pub struct Rarity { pub name: SharedStr, pub color: Color, } impl bevy::asset::Asset for Rarity {} impl bevy::asset::VisitAssetDependencies for Rarity { fn visit_dependencies( &self, _visit: &mut impl FnMut(bevy::asset::UntypedAssetId), // <-- fixed ) {} } impl bevy::reflect::TypePath for Rarity { fn type_path() -> &'static str { "myasset::item::Rarity" } fn short_type_path() -> &'static str { "Rarity" } fn type_ident() -> Option<&'static str> { ::core::option::Option::Some("Rarity") } fn crate_name() -> Option<&'static str> { ::core::option::Option::Some( "myasset::item".split(':').next().unwrap(), ) } fn module_path() -> Option<&'static str> { ::core::option::Option::Some("myasset::item") } } ```
This commit is contained in:
parent
a5a457c3c8
commit
7a72bac779
@ -66,9 +66,16 @@ fn derive_dependency_visitor_internal(
|
||||
let struct_name = &ast.ident;
|
||||
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
|
||||
|
||||
// prevent unused variable warning in case there are no dependencies
|
||||
let visit = if field_visitors.is_empty() {
|
||||
quote! { _visit }
|
||||
} else {
|
||||
quote! { visit }
|
||||
};
|
||||
|
||||
Ok(quote! {
|
||||
impl #impl_generics #bevy_asset_path::VisitAssetDependencies for #struct_name #type_generics #where_clause {
|
||||
fn visit_dependencies(&self, visit: &mut impl FnMut(#bevy_asset_path::UntypedAssetId)) {
|
||||
fn visit_dependencies(&self, #visit: &mut impl FnMut(#bevy_asset_path::UntypedAssetId)) {
|
||||
#(#field_visitors)*
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user