Skip to content

Commit 4198d29

Browse files
committed
Implement masking in FileType hashing on Unix
Commit 7700595 implemented masking of FileType to fix an issue[^1] in the semantic of FileType comparison. This commit introduces masking to Hash to maintain the invariant that x == y => hash(x) == hash(y). [^1]: #104900
1 parent 6259028 commit 4198d29

File tree

1 file changed

+8
-1
lines changed
  • library/std/src/sys/unix

1 file changed

+8
-1
lines changed

library/std/src/sys/unix/fs.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ pub struct FileTimes {
332332
modified: Option<SystemTime>,
333333
}
334334

335-
#[derive(Copy, Clone, Eq, Hash, Debug)]
335+
#[derive(Copy, Clone, Eq, Debug)]
336336
pub struct FileType {
337337
mode: mode_t,
338338
}
@@ -342,6 +342,13 @@ impl PartialEq for FileType {
342342
self.masked() == other.masked()
343343
}
344344
}
345+
346+
impl core::hash::Hash for FileType {
347+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
348+
self.masked().hash(state);
349+
}
350+
}
351+
345352
#[derive(Debug)]
346353
pub struct DirBuilder {
347354
mode: mode_t,

0 commit comments

Comments
 (0)