@@ -72,7 +72,6 @@ macro_rules! define_label {
7272 $( #[ $id_attr] ) *
7373 #[ derive( Clone , Copy ) ]
7474 pub struct $id_name {
75- ty: :: std:: any:: TypeId ,
7675 data: u64 ,
7776 f: fn ( u64 , & mut :: std:: fmt:: Formatter ) -> :: std:: fmt:: Result ,
7877 }
@@ -89,14 +88,8 @@ macro_rules! define_label {
8988 /// Converts this type into an opaque, strongly-typed label.
9089 #[ inline]
9190 fn as_label( & self ) -> $id_name {
92- let ty = self . type_id( ) ;
9391 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 }
10093 }
10194 /// Returns a number used to distinguish different labels of the same type.
10295 fn data( & self ) -> u64 ;
@@ -114,10 +107,6 @@ macro_rules! define_label {
114107 * self
115108 }
116109 #[ inline]
117- fn type_id( & self ) -> :: std:: any:: TypeId {
118- self . ty
119- }
120- #[ inline]
121110 fn data( & self ) -> u64 {
122111 self . data
123112 }
@@ -130,17 +119,27 @@ macro_rules! define_label {
130119 impl PartialEq for $id_name {
131120 #[ inline]
132121 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( )
134123 }
135124 }
136125 impl Eq for $id_name { }
137126
138127
139128 impl std:: hash:: Hash for $id_name {
140129 fn hash<H : std:: hash:: Hasher >( & self , state: & mut H ) {
141- self . type_id ( ) . hash( state) ;
130+ ( self . f as usize ) . hash( state) ;
142131 self . data( ) . hash( state) ;
143132 }
144133 }
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+ }
145144 } ;
146145}
0 commit comments