@@ -13,7 +13,7 @@ pub trait Introspect {
1313/// optimized to avoid heap allocation.
1414///
1515/// To examine a `Type`, you should call the `which()` method.
16- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
16+ #[ derive( Copy , Clone , Debug ) ]
1717pub struct Type {
1818 /// The type, minus any outer `List( )`.
1919 base : BaseType ,
@@ -105,9 +105,9 @@ impl Type {
105105 }
106106 }
107107
108- /// Returns true is a dynamic value of type `self` is
109- /// allowed to be downcast to type `other` .
110- pub ( crate ) fn may_downcast_to ( & self , other : Self ) -> bool {
108+ /// Returns true if `self` is equal to `other` modulo
109+ /// type parameters and interface types .
110+ pub fn loose_equals ( & self , other : Self ) -> bool {
111111 match ( self . which ( ) , other. which ( ) ) {
112112 ( TypeVariant :: Void , TypeVariant :: Void ) => true ,
113113 ( TypeVariant :: UInt8 , TypeVariant :: UInt8 ) => true ,
@@ -133,7 +133,7 @@ impl Type {
133133 core:: ptr:: eq ( rbs1. generic , rbs2. generic )
134134 }
135135 ( TypeVariant :: List ( element1) , TypeVariant :: List ( element2) ) => {
136- element1. may_downcast_to ( element2)
136+ element1. loose_equals ( element2)
137137 }
138138 ( TypeVariant :: AnyPointer , TypeVariant :: AnyPointer ) => true ,
139139 ( TypeVariant :: Capability , TypeVariant :: Capability ) => true ,
@@ -142,7 +142,7 @@ impl Type {
142142 }
143143}
144144
145- #[ derive( Copy , Clone , PartialEq , Eq ) ]
145+ #[ derive( Copy , Clone ) ]
146146/// A `Type` unfolded one level. Suitable for pattern matching. Can be trivially
147147/// converted to `Type` via the `From`/`Into` traits.
148148pub enum TypeVariant {
@@ -194,7 +194,7 @@ impl From<TypeVariant> for Type {
194194}
195195
196196/// A Cap'n Proto type, excluding `List`.
197- #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
197+ #[ derive( Copy , Clone , Debug ) ]
198198enum BaseType {
199199 Void ,
200200 Bool ,
@@ -270,34 +270,6 @@ pub struct RawBrandedStructSchema {
270270 pub annotation_types : fn ( Option < u16 > , u32 ) -> Type ,
271271}
272272
273- /// WARNING!
274- ///
275- /// In capnproto-c++, this method is implemented as a single pointer
276- /// comparison. That works because C++ guarantees unique addresses
277- /// for static template instantiations. In contrast, the below Rust
278- /// implementation uses function pointer comparison, which might
279- /// give unexpected results (particularly in the presence of type
280- /// parameter instantiation).
281- ///
282- /// For this reason, usage of equality on types in capnproto-rust
283- /// is discouraged.
284- ///
285- /// You might think that we could still implement the method
286- /// in a slower way by recursively comparing types of fields.
287- /// However, that (or at least the naive version of it) can hit
288- /// infinite loops because e.g. a struct Foo might have a field of
289- /// type Foo.
290- ///
291- /// TODO(api_bump): remove this `impl PartialEq`.
292- impl core:: cmp:: PartialEq for RawBrandedStructSchema {
293- #[ allow( unpredictable_function_pointer_comparisons) ]
294- fn eq ( & self , other : & Self ) -> bool {
295- core:: ptr:: eq ( self . generic , other. generic ) && self . field_types == other. field_types
296- }
297- }
298-
299- impl core:: cmp:: Eq for RawBrandedStructSchema { }
300-
301273impl core:: fmt:: Debug for RawBrandedStructSchema {
302274 fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: result:: Result < ( ) , core:: fmt:: Error > {
303275 write ! (
0 commit comments