about summary refs log tree commit diff
diff options
context:
space:
mode:
authorxiongmao86 <xiongmao86dev@sina.com>2020-01-02 11:37:32 +0800
committerxiongmao86 <xiongmao86dev@sina.com>2020-01-12 19:54:17 +0800
commit3a788452e2d81273d9c3981e401019bf0f45d78d (patch)
tree46931c2a84ea985cbf535dd68f4bc2e6e598b724
parent2677a4ef02ce309be49643ad7cd0beab6375a0f3 (diff)
downloadrust-3a788452e2d81273d9c3981e401019bf0f45d78d.tar.gz
rust-3a788452e2d81273d9c3981e401019bf0f45d78d.zip
Add test.
-rw-r--r--tests/ui/filetype_is_file.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs
new file mode 100644
index 00000000000..7e85519a518
--- /dev/null
+++ b/tests/ui/filetype_is_file.rs
@@ -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(())
+}
\ No newline at end of file