diff --git a/crates/bevy_utils/src/label.rs b/crates/bevy_utils/src/label.rs index 596731bf554781..48a7bd16834a0c 100644 --- a/crates/bevy_utils/src/label.rs +++ b/crates/bevy_utils/src/label.rs @@ -81,6 +81,7 @@ macro_rules! define_label { $(#[$id_attr])* #[derive(Clone, Copy)] pub struct $id_name { + ty: ::std::any::TypeId, data: u64, f: fn(u64, &mut ::std::fmt::Formatter) -> ::std::fmt::Result, } @@ -98,7 +99,7 @@ macro_rules! define_label { #[inline] fn as_label(&self) -> $id_name { let data = self.data(); - $id_name { data, f: Self::fmt } + $id_name { data, ty: ::std::any::TypeId::of::(), f: Self::fmt } } /// Returns a number used to distinguish different labels of the same type. fn data(&self) -> u64; @@ -128,7 +129,7 @@ macro_rules! define_label { impl PartialEq for $id_name { #[inline] fn eq(&self, rhs: &Self) -> bool { - (self.f as usize) == (rhs.f as usize) && self.data() == rhs.data() + self.ty == rhs.ty && self.data() == rhs.data() } } impl Eq for $id_name {} @@ -136,7 +137,7 @@ macro_rules! define_label { impl std::hash::Hash for $id_name { fn hash(&self, state: &mut H) { - (self.f as usize).hash(state); + self.ty.hash(state); self.data().hash(state); } } @@ -144,10 +145,7 @@ macro_rules! define_label { impl $id_name { /// Returns true if this label was constructed from an instance of type `L`. pub fn is(self) -> bool { - // FIXME: This is potentially incorrect, due to the - // compiler unifying identical functions. We'll likely - // have to store some kind of hash of the TypeId. - (self.f as usize) == (::fmt as usize) + self.ty == ::std::any::TypeId::of::() } /// Attempts to downcast this label to type `L`. ///