@@ -81,6 +81,7 @@ macro_rules! define_label {
81
81
$( #[ $id_attr] ) *
82
82
#[ derive( Clone , Copy ) ]
83
83
pub struct $id_name {
84
+ ty: :: std:: any:: TypeId ,
84
85
data: u64 ,
85
86
f: fn ( u64 , & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result ,
86
87
}
@@ -98,7 +99,7 @@ macro_rules! define_label {
98
99
#[ inline]
99
100
fn as_label( & self ) -> $id_name {
100
101
let data = self . data( ) ;
101
- $id_name { data, f: Self :: fmt }
102
+ $id_name { data, ty : :: std :: any :: TypeId :: of :: < Self > ( ) , f: Self :: fmt }
102
103
}
103
104
/// Returns a number used to distinguish different labels of the same type.
104
105
fn data( & self ) -> u64 ;
@@ -128,26 +129,23 @@ macro_rules! define_label {
128
129
impl PartialEq for $id_name {
129
130
#[ inline]
130
131
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( )
132
133
}
133
134
}
134
135
impl Eq for $id_name { }
135
136
136
137
137
138
impl std:: hash:: Hash for $id_name {
138
139
fn hash<H : std:: hash:: Hasher >( & self , state: & mut H ) {
139
- ( self . f as usize ) . hash( state) ;
140
+ self . ty . hash( state) ;
140
141
self . data( ) . hash( state) ;
141
142
}
142
143
}
143
144
144
145
impl $id_name {
145
146
/// Returns true if this label was constructed from an instance of type `L`.
146
147
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 >( )
151
149
}
152
150
/// Attempts to downcast this label to type `L`.
153
151
///
0 commit comments