-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
File and Metadata should document reasons to prefer *not* to use is_file() #64170
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
As per rust-lang/rust-clippy#4503, there's a bit of a trap you can fall into if you use
is_file()as a predictor for "can I probably open and read bytes from this thing".You generally don't want to assert
is_file()for user specified paths, especially if they come from command line arguments, where they might be Unix FIFO File Descriptors.If for example you were implementing
catin rust, usingis_file()instead of!is_dir()would prevent you from reading block devices, character devices, pipes, and more:And this would break your ability to be composed nicely in Unix flows where patterns like:
Would become broken if diff was a rust program that ensured all its arguments were
is_file()