Skip to content

Commit 239f8dc

Browse files
committed
undo an optimization 😭
MIRI is buggy so we can't use fn pointers for comparisons
1 parent 8bce742 commit 239f8dc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

crates/bevy_utils/src/label.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ macro_rules! define_label {
8181
$(#[$id_attr])*
8282
#[derive(Clone, Copy)]
8383
pub struct $id_name {
84+
ty: ::std::any::TypeId,
8485
data: u64,
8586
f: fn(u64, &mut ::std::fmt::Formatter) -> ::std::fmt::Result,
8687
}
@@ -98,7 +99,7 @@ macro_rules! define_label {
9899
#[inline]
99100
fn as_label(&self) -> $id_name {
100101
let data = self.data();
101-
$id_name { data, f: Self::fmt }
102+
$id_name { data, ty: ::std::any::TypeId::of::<Self>(), f: Self::fmt }
102103
}
103104
/// Returns a number used to distinguish different labels of the same type.
104105
fn data(&self) -> u64;
@@ -128,26 +129,23 @@ macro_rules! define_label {
128129
impl PartialEq for $id_name {
129130
#[inline]
130131
fn eq(&self, rhs: &Self) -> bool {
131-
(self.f as usize) == (rhs.f as usize) && self.data() == rhs.data()
132+
self.ty == rhs.ty && self.data() == rhs.data()
132133
}
133134
}
134135
impl Eq for $id_name {}
135136

136137

137138
impl std::hash::Hash for $id_name {
138139
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
139-
(self.f as usize).hash(state);
140+
self.ty.hash(state);
140141
self.data().hash(state);
141142
}
142143
}
143144

144145
impl $id_name {
145146
/// Returns true if this label was constructed from an instance of type `L`.
146147
pub fn is<L: $label_name>(self) -> bool {
147-
// FIXME: This is potentially incorrect, due to the
148-
// compiler unifying identical functions. We'll likely
149-
// have to store some kind of hash of the TypeId.
150-
(self.f as usize) == (<L as $label_name>::fmt as usize)
148+
self.ty == ::std::any::TypeId::of::<L>()
151149
}
152150
/// Attempts to downcast this label to type `L`.
153151
///

0 commit comments

Comments
 (0)