Skip to content

Inconsistent behavior in FileType comparisons on Windows #138668

Closed
@mikerooni

Description

@mikerooni

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions