@@ -103,6 +103,7 @@ use borrow::{Borrow, IntoCow, ToOwned, Cow};
103
103
use cmp;
104
104
use fmt;
105
105
use fs;
106
+ use hash:: { Hash , Hasher } ;
106
107
use io;
107
108
use iter;
108
109
use mem;
@@ -446,7 +447,7 @@ enum State {
446
447
///
447
448
/// Does not occur on Unix.
448
449
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
449
- #[ derive( Copy , Clone , Eq , Hash , Debug ) ]
450
+ #[ derive( Copy , Clone , Eq , Debug ) ]
450
451
pub struct PrefixComponent < ' a > {
451
452
/// The prefix as an unparsed `OsStr` slice.
452
453
raw : & ' a OsStr ,
@@ -490,6 +491,13 @@ impl<'a> cmp::Ord for PrefixComponent<'a> {
490
491
}
491
492
}
492
493
494
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
495
+ impl < ' a > Hash for PrefixComponent < ' a > {
496
+ fn hash < H : Hasher > ( & self , h : & mut H ) {
497
+ self . parsed . hash ( h) ;
498
+ }
499
+ }
500
+
493
501
/// A single component of a path.
494
502
///
495
503
/// See the module documentation for an in-depth explanation of components and
@@ -932,7 +940,7 @@ impl<'a> cmp::Ord for Components<'a> {
932
940
/// path.push("system32");
933
941
/// path.set_extension("dll");
934
942
/// ```
935
- #[ derive( Clone , Hash ) ]
943
+ #[ derive( Clone ) ]
936
944
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
937
945
pub struct PathBuf {
938
946
inner : OsString
@@ -1171,6 +1179,13 @@ impl cmp::PartialEq for PathBuf {
1171
1179
}
1172
1180
}
1173
1181
1182
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1183
+ impl Hash for PathBuf {
1184
+ fn hash < H : Hasher > ( & self , h : & mut H ) {
1185
+ self . as_path ( ) . hash ( h)
1186
+ }
1187
+ }
1188
+
1174
1189
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1175
1190
impl cmp:: Eq for PathBuf { }
1176
1191
@@ -1224,7 +1239,6 @@ impl Into<OsString> for PathBuf {
1224
1239
/// let parent_dir = path.parent();
1225
1240
/// ```
1226
1241
///
1227
- #[ derive( Hash ) ]
1228
1242
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1229
1243
pub struct Path {
1230
1244
inner : OsStr
@@ -1809,6 +1823,15 @@ impl cmp::PartialEq for Path {
1809
1823
}
1810
1824
}
1811
1825
1826
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1827
+ impl Hash for Path {
1828
+ fn hash < H : Hasher > ( & self , h : & mut H ) {
1829
+ for component in self . components ( ) {
1830
+ component. hash ( h) ;
1831
+ }
1832
+ }
1833
+ }
1834
+
1812
1835
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1813
1836
impl cmp:: Eq for Path { }
1814
1837
@@ -3035,6 +3058,14 @@ mod tests {
3035
3058
3036
3059
#[ test]
3037
3060
pub fn test_compare ( ) {
3061
+ use hash:: { Hash , Hasher , SipHasher } ;
3062
+
3063
+ fn hash < T : Hash > ( t : T ) -> u64 {
3064
+ let mut s = SipHasher :: new_with_keys ( 0 , 0 ) ;
3065
+ t. hash ( & mut s) ;
3066
+ s. finish ( )
3067
+ }
3068
+
3038
3069
macro_rules! tc(
3039
3070
( $path1: expr, $path2: expr, eq: $eq: expr,
3040
3071
starts_with: $starts_with: expr, ends_with: $ends_with: expr,
@@ -3045,6 +3076,9 @@ mod tests {
3045
3076
let eq = path1 == path2;
3046
3077
assert!( eq == $eq, "{:?} == {:?}, expected {:?}, got {:?}" ,
3047
3078
$path1, $path2, $eq, eq) ;
3079
+ assert!( $eq == ( hash( path1) == hash( path2) ) ,
3080
+ "{:?} == {:?}, expected {:?}, got {} and {}" ,
3081
+ $path1, $path2, $eq, hash( path1) , hash( path2) ) ;
3048
3082
3049
3083
let starts_with = path1. starts_with( path2) ;
3050
3084
assert!( starts_with == $starts_with,
0 commit comments