From 3a788452e2d81273d9c3981e401019bf0f45d78d Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Thu, 2 Jan 2020 11:37:32 +0800 Subject: [PATCH] Add test. --- tests/ui/filetype_is_file.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/ui/filetype_is_file.rs diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs new file mode 100644 index 000000000..7e85519a5 --- /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