]> git.lizzy.rs Git - rust.git/blob - src/docs/filetype_is_file.txt
Add iter_kv_map lint
[rust.git] / src / docs / filetype_is_file.txt
1 ### What it does
2 Checks for `FileType::is_file()`.
3
4 ### Why is this bad?
5 When people testing a file type with `FileType::is_file`
6 they are testing whether a path is something they can get bytes from. But
7 `is_file` doesn't cover special file types in unix-like systems, and doesn't cover
8 symlink in windows. Using `!FileType::is_dir()` is a better way to that intention.
9
10 ### Example
11 ```
12 let metadata = std::fs::metadata("foo.txt")?;
13 let filetype = metadata.file_type();
14
15 if filetype.is_file() {
16     // read file
17 }
18 ```
19
20 should be written as:
21
22 ```
23 let metadata = std::fs::metadata("foo.txt")?;
24 let filetype = metadata.file_type();
25
26 if !filetype.is_dir() {
27     // read file
28 }
29 ```