diff --git a/crates/bevy_macro_utils/src/label.rs b/crates/bevy_macro_utils/src/label.rs index 6eec83c04c..1fc540c9c4 100644 --- a/crates/bevy_macro_utils/src/label.rs +++ b/crates/bevy_macro_utils/src/label.rs @@ -81,21 +81,26 @@ pub fn derive_label( .unwrap(), ); quote! { - impl #impl_generics #trait_path for #ident #ty_generics #where_clause { - fn dyn_clone(&self) -> ::std::boxed::Box { - ::std::boxed::Box::new(::core::clone::Clone::clone(self)) - } + // To ensure alloc is available, but also prevent its name from clashing, we place the implementation inside an anonymous constant + const _: () = { + extern crate alloc; - fn as_dyn_eq(&self) -> &dyn #dyn_eq_path { - self - } + impl #impl_generics #trait_path for #ident #ty_generics #where_clause { + fn dyn_clone(&self) -> alloc::boxed::Box { + alloc::boxed::Box::new(::core::clone::Clone::clone(self)) + } - fn dyn_hash(&self, mut state: &mut dyn ::core::hash::Hasher) { - let ty_id = ::core::any::TypeId::of::(); - ::core::hash::Hash::hash(&ty_id, &mut state); - ::core::hash::Hash::hash(self, &mut state); + fn as_dyn_eq(&self) -> &dyn #dyn_eq_path { + self + } + + fn dyn_hash(&self, mut state: &mut dyn ::core::hash::Hasher) { + let ty_id = ::core::any::TypeId::of::(); + ::core::hash::Hash::hash(&ty_id, &mut state); + ::core::hash::Hash::hash(self, &mut state); + } } - } + }; } .into() }