-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #4543 - xiongmao86:issue4503, r=flip1995
Fix issue4503 Fixes #4503. changelog: Add a lint checking user are using FileType.is_file() method and suggest using !FileType.is_dir(). - [x] Followed [lint naming conventions][lint_naming] - [x] Added passing UI tests (including committed `.stderr` file) - [x] `cargo test` passes locally - [x] Executed `./util/dev update_lints` - [x] Added lint documentation - [x] Run `./util/dev fmt`
- Loading branch information
Showing
9 changed files
with
132 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![warn(clippy::filetype_is_file)] | ||
|
||
fn main() -> std::io::Result<()> { | ||
use std::fs; | ||
use std::ops::BitOr; | ||
|
||
// !filetype.is_dir() | ||
if fs::metadata("foo.txt")?.file_type().is_file() { | ||
// read file | ||
} | ||
|
||
// positive of filetype.is_dir() | ||
if !fs::metadata("foo.txt")?.file_type().is_file() { | ||
// handle dir | ||
} | ||
|
||
// false positive of filetype.is_dir() | ||
if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { | ||
// ... | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: `FileType::is_file()` only covers regular files | ||
--> $DIR/filetype_is_file.rs:8:8 | ||
| | ||
LL | if fs::metadata("foo.txt")?.file_type().is_file() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::filetype-is-file` implied by `-D warnings` | ||
= help: use `!FileType::is_dir()` instead | ||
|
||
error: `!FileType::is_file()` only denies regular files | ||
--> $DIR/filetype_is_file.rs:13:8 | ||
| | ||
LL | if !fs::metadata("foo.txt")?.file_type().is_file() { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use `FileType::is_dir()` instead | ||
|
||
error: `FileType::is_file()` only covers regular files | ||
--> $DIR/filetype_is_file.rs:18:9 | ||
| | ||
LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: use `!FileType::is_dir()` instead | ||
|
||
error: aborting due to 3 previous errors | ||
|