@@ -29,8 +29,7 @@ struct PackageIdInner {
29
29
source_id : SourceId ,
30
30
}
31
31
32
- // Custom equality that uses full equality of SourceId, rather than its custom equality,
33
- // and Version, which usually ignores `build` metadata.
32
+ // Custom equality that uses full equality of SourceId, rather than its custom equality.
34
33
//
35
34
// The `build` part of the version is usually ignored (like a "comment").
36
35
// However, there are some cases where it is important. The download path from
@@ -40,11 +39,7 @@ struct PackageIdInner {
40
39
impl PartialEq for PackageIdInner {
41
40
fn eq ( & self , other : & Self ) -> bool {
42
41
self . name == other. name
43
- && self . version . major == other. version . major
44
- && self . version . minor == other. version . minor
45
- && self . version . patch == other. version . patch
46
- && self . version . pre == other. version . pre
47
- && self . version . build == other. version . build
42
+ && self . version == other. version
48
43
&& self . source_id . full_eq ( other. source_id )
49
44
}
50
45
}
@@ -53,11 +48,7 @@ impl PartialEq for PackageIdInner {
53
48
impl Hash for PackageIdInner {
54
49
fn hash < S : hash:: Hasher > ( & self , into : & mut S ) {
55
50
self . name . hash ( into) ;
56
- self . version . major . hash ( into) ;
57
- self . version . minor . hash ( into) ;
58
- self . version . patch . hash ( into) ;
59
- self . version . pre . hash ( into) ;
60
- self . version . build . hash ( into) ;
51
+ self . version . hash ( into) ;
61
52
self . source_id . full_hash ( into) ;
62
53
}
63
54
}
@@ -233,6 +224,16 @@ impl fmt::Debug for PackageId {
233
224
}
234
225
}
235
226
227
+ impl fmt:: Debug for PackageIdInner {
228
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
229
+ f. debug_struct ( "PackageIdInner" )
230
+ . field ( "name" , & self . name )
231
+ . field ( "version" , & self . version . to_string ( ) )
232
+ . field ( "source" , & self . source_id . to_string ( ) )
233
+ . finish ( )
234
+ }
235
+ }
236
+
236
237
#[ cfg( test) ]
237
238
mod tests {
238
239
use super :: PackageId ;
@@ -257,4 +258,14 @@ mod tests {
257
258
let pkg_id = PackageId :: new ( "foo" , "1.0.0" , SourceId :: for_registry ( & loc) . unwrap ( ) ) . unwrap ( ) ;
258
259
assert_eq ! ( "foo v1.0.0" , pkg_id. to_string( ) ) ;
259
260
}
261
+
262
+ #[ test]
263
+ fn unequal_build_metadata ( ) {
264
+ let loc = CRATES_IO_INDEX . into_url ( ) . unwrap ( ) ;
265
+ let repo = SourceId :: for_registry ( & loc) . unwrap ( ) ;
266
+ let first = PackageId :: new ( "foo" , "0.0.1+first" , repo) . unwrap ( ) ;
267
+ let second = PackageId :: new ( "foo" , "0.0.1+second" , repo) . unwrap ( ) ;
268
+ assert_ne ! ( first, second) ;
269
+ assert_ne ! ( first. inner, second. inner) ;
270
+ }
260
271
}
0 commit comments