Inconsistent behavior in FileType comparisons on Windows · Issue #138668 · rust-lang/rust (original) (raw)

The PartialEq/Eq implementation of FileType on Windows is currently comparing more than just the actual file type. It seems to be using all file attributes for the comparison instead.

Steps to reproduce:

  1. Create two files, e.g. a.txt and b.txt
  2. Using Windows Explorer:
    • Right click -> Properties -> open the "Advanced" file attributes dialog
    • Enable "Allow this file to have contents indexed in addition to file properties" for only one of these files, but not the other

The following test will now fail:

let type_a = fs::metadata("a.txt").unwrap().file_type(); let type_b = fs::metadata("b.txt").unwrap().file_type(); assert_eq!(type_a, type_b);

Expected behavior:

I would expect the comparison between two FileTypes to only compare the actual file TYPE (e.g. file, dir, symlink, any platform-specific extensions), but not file attributes.

Another issue in this case is that it isn't obvious why the comparison fails, because FileType's Debug implementation only shows is_file, is_dir, and is_symlink:

assertion `left == right` failed
  left: FileType { is_file: true, is_dir: false, is_symlink: false, .. }
 right: FileType { is_file: true, is_dir: false, is_symlink: false, .. }

I'm not sure whether this is something that can be easily fixed - I'd argue it should be considered an actual bug occurring in an edge case, but fixing it would technically introduce a breaking change.

rustc --version --verbose:

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-pc-windows-msvc
release: 1.85.0
LLVM version: 19.1.7