File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,12 @@ mod structs {
106106 field2 : bool ,
107107 }
108108
109+ #[ derive( Hash ) ]
110+ struct PossibleCollision {
111+ a : & ' static str ,
112+ b : & ' static str ,
113+ }
114+
109115 #[ test]
110116 fn assert ( ) {
111117 assert_eq ! (
@@ -136,6 +142,10 @@ mod structs {
136142 } ) ,
137143 do_hash( & ( 42 , true ) )
138144 ) ;
145+ assert_ne ! (
146+ do_hash( & PossibleCollision { a: "a" , b: "bc" } ) ,
147+ do_hash( & PossibleCollision { a: "ab" , b: "c" } )
148+ ) ;
139149 }
140150 }
141151
@@ -188,6 +198,13 @@ mod enums {
188198 C ,
189199 }
190200
201+ #[ derive( Hash ) ]
202+ enum SameDataEnum {
203+ A ( i32 ) ,
204+ B ( i32 ) ,
205+ C ( i32 ) ,
206+ }
207+
191208 #[ derive( Hash ) ]
192209 enum StructEnum {
193210 A { x : i32 } ,
@@ -227,6 +244,12 @@ mod enums {
227244 do_hash( & SimpleEnum :: C ) ,
228245 do_hash( & core:: mem:: discriminant( & SimpleEnum :: C ) )
229246 ) ;
247+ let sa = SameDataEnum :: A ( 42 ) ;
248+ assert_eq ! ( do_hash( & sa) , do_hash( & ( core:: mem:: discriminant( & sa) , 42 ) ) ) ;
249+ let sb = SameDataEnum :: B ( 42 ) ;
250+ assert_eq ! ( do_hash( & sb) , do_hash( & ( core:: mem:: discriminant( & sb) , 42 ) ) ) ;
251+ let sc = SameDataEnum :: C ( 42 ) ;
252+ assert_eq ! ( do_hash( & sc) , do_hash( & ( core:: mem:: discriminant( & sc) , 42 ) ) ) ;
230253 let ta = TupleEnum :: A ( 42 ) ;
231254 let tb = TupleEnum :: B ( "test" , true ) ;
232255 assert_eq ! ( do_hash( & ta) , do_hash( & ( core:: mem:: discriminant( & ta) , 42 ) ) ) ;
You can’t perform that action at this time.
0 commit comments