@@ -72,7 +72,6 @@ macro_rules! define_label {
72
72
$( #[ $id_attr] ) *
73
73
#[ derive( Clone , Copy ) ]
74
74
pub struct $id_name {
75
- ty: :: std:: any:: TypeId ,
76
75
data: u64 ,
77
76
f: fn ( u64 , & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result ,
78
77
}
@@ -89,14 +88,8 @@ macro_rules! define_label {
89
88
/// Converts this type into an opaque, strongly-typed label.
90
89
#[ inline]
91
90
fn as_label( & self ) -> $id_name {
92
- let ty = self . type_id( ) ;
93
91
let data = self . data( ) ;
94
- $id_name { ty, data, f: Self :: fmt }
95
- }
96
- /// Returns the [`TypeId`] used to differentiate labels.
97
- #[ inline]
98
- fn type_id( & self ) -> :: std:: any:: TypeId {
99
- :: std:: any:: TypeId :: of:: <Self >( )
92
+ $id_name { data, f: Self :: fmt }
100
93
}
101
94
/// Returns a number used to distinguish different labels of the same type.
102
95
fn data( & self ) -> u64 ;
@@ -114,10 +107,6 @@ macro_rules! define_label {
114
107
* self
115
108
}
116
109
#[ inline]
117
- fn type_id( & self ) -> :: std:: any:: TypeId {
118
- self . ty
119
- }
120
- #[ inline]
121
110
fn data( & self ) -> u64 {
122
111
self . data
123
112
}
@@ -130,17 +119,27 @@ macro_rules! define_label {
130
119
impl PartialEq for $id_name {
131
120
#[ inline]
132
121
fn eq( & self , rhs: & Self ) -> bool {
133
- self . type_id ( ) == rhs. type_id ( ) && self . data( ) == rhs. data( )
122
+ ( self . f as usize ) == ( rhs. f as usize ) && self . data( ) == rhs. data( )
134
123
}
135
124
}
136
125
impl Eq for $id_name { }
137
126
138
127
139
128
impl std:: hash:: Hash for $id_name {
140
129
fn hash<H : std:: hash:: Hasher >( & self , state: & mut H ) {
141
- self . type_id ( ) . hash( state) ;
130
+ ( self . f as usize ) . hash( state) ;
142
131
self . data( ) . hash( state) ;
143
132
}
144
133
}
134
+
135
+ impl $id_name {
136
+ /// Returns true if this label was constructed from an instance of type `L`.
137
+ pub fn is<L : $label_name>( self ) -> bool {
138
+ // FIXME: This is potentially incorrect, due to the
139
+ // compiler unifying identical functions. We'll likely
140
+ // have to store some kind of hash of the TypeId.
141
+ ( self . f as usize ) == ( <L as $label_name>:: fmt as usize )
142
+ }
143
+ }
145
144
} ;
146
145
}
0 commit comments