From 3a788452e2d81273d9c3981e401019bf0f45d78d Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Thu, 2 Jan 2020 11:37:32 +0800 Subject: [PATCH 01/13] 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 000000000000..7e85519a518f --- /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 From 96334d0d7cc2901acc80a67ba454409dcd452a30 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Thu, 2 Jan 2020 13:12:23 +0800 Subject: [PATCH 02/13] Declare lint. --- CHANGELOG.md | 1 + clippy_lints/src/lib.rs | 3 +++ clippy_lints/src/methods/mod.rs | 35 +++++++++++++++++++++++++++++++++ src/lintlist/mod.rs | 7 +++++++ 4 files changed, 46 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69694da15203..11d745a4c23c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1093,6 +1093,7 @@ Released 2018-09-13 [`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice [`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes [`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from +[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file [`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map [`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next [`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1a112c0d3709..85cca4a77fe4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -612,6 +612,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf &methods::CLONE_ON_COPY, &methods::CLONE_ON_REF_PTR, &methods::EXPECT_FUN_CALL, + &methods::FILETYPE_IS_FILE, &methods::FILTER_MAP, &methods::FILTER_MAP_NEXT, &methods::FILTER_NEXT, @@ -1199,6 +1200,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&methods::CLONE_DOUBLE_REF), LintId::of(&methods::CLONE_ON_COPY), LintId::of(&methods::EXPECT_FUN_CALL), + LintId::of(&methods::FILETYPE_IS_FILE), LintId::of(&methods::FILTER_NEXT), LintId::of(&methods::FLAT_MAP_IDENTITY), LintId::of(&methods::INEFFICIENT_TO_STRING), @@ -1384,6 +1386,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(&methods::CHARS_LAST_CMP), + LintId::of(&methods::FILETYPE_IS_FILE), LintId::of(&methods::INTO_ITER_ON_REF), LintId::of(&methods::ITER_CLONED_COLLECT), LintId::of(&methods::ITER_NTH_ZERO), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 073177b0f3d5..b5f68817c358 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1130,6 +1130,40 @@ declare_clippy_lint! { "Check for offset calculations on raw pointers to zero-sized types" } +declare_clippy_lint! { + /// **What it does:** Checks for `FileType::is_file()`. + /// + /// **Why is this bad?** When people testing a file type with `FileType::is_file` + /// they are testing whether a path is something they can get bytes from. But + /// `is_file` doesn't cover special file types in unix-like systems. and not covering + /// symlink in windows. Using `!FileType::is_dir()` is a better way to that intention. + /// + /// **Example:** + /// + /// ```rust,ignore + /// let metadata = std::fs::metadata("foo.txt")?; + /// let filetype = metadata.file_type(); + /// + /// if filetype.is_file() { + /// // read file + /// } + /// ``` + /// + /// should be writing as: + /// + /// ```rust,ignore + /// let metadata = std::fs::metadata("foo.txt")?; + /// let filetype = metadata.file_type(); + /// + /// if !filetype.is_dir() { + /// // read file + /// } + /// ``` + pub FILETYPE_IS_FILE, + style, + "`FileType::is_file` is not recommended to test for readable file type." +} + declare_lint_pass!(Methods => [ OPTION_UNWRAP_USED, RESULT_UNWRAP_USED, @@ -1177,6 +1211,7 @@ declare_lint_pass!(Methods => [ UNINIT_ASSUMED_INIT, MANUAL_SATURATING_ARITHMETIC, ZST_OFFSET, + FILETYPE_IS_FILE, ]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index f576bb152de9..5dd82b66b8e8 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -560,6 +560,13 @@ pub const ALL_LINTS: [Lint; 346] = [ deprecation: None, module: "fallible_impl_from", }, + Lint { + name: "filetype_is_file", + group: "style", + desc: "`FileType::is_file` is not recommended to test for readable file type.", + deprecation: None, + module: "methods", + }, Lint { name: "filter_map", group: "pedantic", From 3c59eaf91cd4cb12397fbcf963f751082afbe532 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Fri, 3 Jan 2020 14:59:14 +0800 Subject: [PATCH 03/13] Add lint logic. --- clippy_lints/src/methods/mod.rs | 24 ++++++++++++++++++++++++ clippy_lints/src/utils/paths.rs | 1 + tests/ui/filetype_is_file.stderr | 27 +++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 tests/ui/filetype_is_file.stderr diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index b5f68817c358..b833fb55157d 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1275,6 +1275,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods { ["add"] | ["offset"] | ["sub"] | ["wrapping_offset"] | ["wrapping_add"] | ["wrapping_sub"] => { check_pointer_offset(cx, expr, arg_lists[0]) }, + ["is_file", ..] => lint_filetype_is_file(cx, expr, arg_lists[0]), _ => {}, } @@ -3259,3 +3260,26 @@ fn check_pointer_offset(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[ } } } + +fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) { + let ty = cx.tables.expr_ty(&args[0]); + + if !match_type(cx, ty, &paths::FILE_TYPE) { + return; + } + + if_chain! { + if let Some(parent) = get_parent_expr(cx, expr); + if let hir::ExprKind::Unary(op, _) = parent.kind; + if op == hir::UnNot; + then { + let lint_msg = "`!FileType::is_file()` does not deny all readable file types"; + let help_msg = "use `FileType::is_dir()` instead"; + span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg); + } else { + let lint_msg = "`FileType::is_file()` does not cover all readable file types"; + let help_msg = "use `!FileType::is_dir()` instead"; + span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg); + } + } +} diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs index 9338daf05741..4f8fe02dfd20 100644 --- a/clippy_lints/src/utils/paths.rs +++ b/clippy_lints/src/utils/paths.rs @@ -28,6 +28,7 @@ pub const DROP_TRAIT: [&str; 4] = ["core", "ops", "drop", "Drop"]; pub const DURATION: [&str; 3] = ["core", "time", "Duration"]; pub const EARLY_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "EarlyContext"]; pub const EXIT: [&str; 3] = ["std", "process", "exit"]; +pub const FILE_TYPE: [&str; 3] = ["std", "fs", "FileType"]; pub const FMT_ARGUMENTS_NEW_V1: [&str; 4] = ["core", "fmt", "Arguments", "new_v1"]; pub const FMT_ARGUMENTS_NEW_V1_FORMATTED: [&str; 4] = ["core", "fmt", "Arguments", "new_v1_formatted"]; pub const FMT_ARGUMENTV1_NEW: [&str; 4] = ["core", "fmt", "ArgumentV1", "new"]; diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr new file mode 100644 index 000000000000..298cb5ad0657 --- /dev/null +++ b/tests/ui/filetype_is_file.stderr @@ -0,0 +1,27 @@ +error: `FileType::is_file()` does not cover all readable file types + --> $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()` does not deny all readable file types + --> $DIR/filetype_is_file.rs:13:9 + | +LL | if !fs::metadata("foo.txt")?.file_type().is_file() { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: use `FileType::is_dir()` instead + +error: `FileType::is_file()` does not cover all readable file types + --> $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 + From a1f81355a7574aaccf540cf1742c90f67fd964d5 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Sat, 4 Jan 2020 10:18:58 +0800 Subject: [PATCH 04/13] format codebase. --- tests/ui/filetype_is_file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/filetype_is_file.rs b/tests/ui/filetype_is_file.rs index 7e85519a518f..5de8fe8cdd7b 100644 --- a/tests/ui/filetype_is_file.rs +++ b/tests/ui/filetype_is_file.rs @@ -20,4 +20,4 @@ fn main() -> std::io::Result<()> { } Ok(()) -} \ No newline at end of file +} From bf9e6ca9f62b0adee51708950ed2cb10e16a7c62 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Sat, 4 Jan 2020 11:24:09 +0800 Subject: [PATCH 05/13] Fix lint warning in compile-test.rs --- tests/compile-test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compile-test.rs b/tests/compile-test.rs index 43139e95666e..5c05e74dcb6d 100644 --- a/tests/compile-test.rs +++ b/tests/compile-test.rs @@ -121,7 +121,7 @@ fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec Date: Sat, 4 Jan 2020 11:27:24 +0800 Subject: [PATCH 06/13] Extend spans to include !. --- clippy_lints/src/methods/mod.rs | 2 +- tests/ui/filetype_is_file.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index b833fb55157d..a56334dc150f 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3275,7 +3275,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: & then { let lint_msg = "`!FileType::is_file()` does not deny all readable file types"; let help_msg = "use `FileType::is_dir()` instead"; - span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg); + span_help_and_lint(cx, FILETYPE_IS_FILE, parent.span, lint_msg, help_msg); } else { let lint_msg = "`FileType::is_file()` does not cover all readable file types"; let help_msg = "use `!FileType::is_dir()` instead"; diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 298cb5ad0657..08bebbd796ed 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -8,10 +8,10 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() { = help: use `!FileType::is_dir()` instead error: `!FileType::is_file()` does not deny all readable file types - --> $DIR/filetype_is_file.rs:13:9 + --> $DIR/filetype_is_file.rs:13:8 | LL | if !fs::metadata("foo.txt")?.file_type().is_file() { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use `FileType::is_dir()` instead From a73822d3b919fa6d5dde92f345c12fd88ba9f56e Mon Sep 17 00:00:00 2001 From: Rui Date: Sun, 5 Jan 2020 20:25:07 +0800 Subject: [PATCH 07/13] Fix documents and messages. Update clippy_lints/src/methods/mod.rs --- clippy_lints/src/methods/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index a56334dc150f..4c372e019dc5 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1135,7 +1135,7 @@ declare_clippy_lint! { /// /// **Why is this bad?** When people testing a file type with `FileType::is_file` /// they are testing whether a path is something they can get bytes from. But - /// `is_file` doesn't cover special file types in unix-like systems. and not covering + /// `is_file` doesn't cover special file types in unix-like systems, and doesn't cover /// symlink in windows. Using `!FileType::is_dir()` is a better way to that intention. /// /// **Example:** @@ -1149,7 +1149,7 @@ declare_clippy_lint! { /// } /// ``` /// - /// should be writing as: + /// should be written as: /// /// ```rust,ignore /// let metadata = std::fs::metadata("foo.txt")?; @@ -1160,8 +1160,8 @@ declare_clippy_lint! { /// } /// ``` pub FILETYPE_IS_FILE, - style, - "`FileType::is_file` is not recommended to test for readable file type." + restriction, + "`FileType::is_file` is not recommended to test for readable file type" } declare_lint_pass!(Methods => [ From 2909bc372fb51fe21be59aca3950eca9ad1514d8 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Tue, 7 Jan 2020 16:11:34 +0800 Subject: [PATCH 08/13] ./util/dev update_lints. --- clippy_lints/src/lib.rs | 3 +-- src/lintlist/mod.rs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 85cca4a77fe4..9ee849ce1627 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -1006,6 +1006,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM), LintId::of(&mem_forget::MEM_FORGET), LintId::of(&methods::CLONE_ON_REF_PTR), + LintId::of(&methods::FILETYPE_IS_FILE), LintId::of(&methods::GET_UNWRAP), LintId::of(&methods::OPTION_EXPECT_USED), LintId::of(&methods::OPTION_UNWRAP_USED), @@ -1200,7 +1201,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&methods::CLONE_DOUBLE_REF), LintId::of(&methods::CLONE_ON_COPY), LintId::of(&methods::EXPECT_FUN_CALL), - LintId::of(&methods::FILETYPE_IS_FILE), LintId::of(&methods::FILTER_NEXT), LintId::of(&methods::FLAT_MAP_IDENTITY), LintId::of(&methods::INEFFICIENT_TO_STRING), @@ -1386,7 +1386,6 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf LintId::of(&mem_replace::MEM_REPLACE_OPTION_WITH_NONE), LintId::of(&mem_replace::MEM_REPLACE_WITH_DEFAULT), LintId::of(&methods::CHARS_LAST_CMP), - LintId::of(&methods::FILETYPE_IS_FILE), LintId::of(&methods::INTO_ITER_ON_REF), LintId::of(&methods::ITER_CLONED_COLLECT), LintId::of(&methods::ITER_NTH_ZERO), diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 5dd82b66b8e8..8554de78d859 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -562,8 +562,8 @@ pub const ALL_LINTS: [Lint; 346] = [ }, Lint { name: "filetype_is_file", - group: "style", - desc: "`FileType::is_file` is not recommended to test for readable file type.", + group: "restriction", + desc: "`FileType::is_file` is not recommended to test for readable file type", deprecation: None, module: "methods", }, From 8d3cc6b8a970efa656a446bbd040d30e5c248501 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Tue, 7 Jan 2020 16:33:33 +0800 Subject: [PATCH 09/13] Change lint message. --- clippy_lints/src/methods/mod.rs | 21 +++++++++++++++------ tests/ui/filetype_is_file.stderr | 6 +++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 4c372e019dc5..2798f6f74abb 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3268,18 +3268,27 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: & return; } + let span: &hir::Expr<'_>; + let verb: &str; + let lint_unary: &str; + let help_unary: &str; if_chain! { if let Some(parent) = get_parent_expr(cx, expr); if let hir::ExprKind::Unary(op, _) = parent.kind; if op == hir::UnNot; then { - let lint_msg = "`!FileType::is_file()` does not deny all readable file types"; - let help_msg = "use `FileType::is_dir()` instead"; - span_help_and_lint(cx, FILETYPE_IS_FILE, parent.span, lint_msg, help_msg); + lint_unary = "!"; + verb = "denys"; + help_unary = ""; + span = parent; } else { - let lint_msg = "`FileType::is_file()` does not cover all readable file types"; - let help_msg = "use `!FileType::is_dir()` instead"; - span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg); + lint_unary = ""; + verb = "covers"; + help_unary = "!"; + span = expr; } } + let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb); + let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary); + span_help_and_lint(cx, FILETYPE_IS_FILE, span.span, &lint_msg, &help_msg); } diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 08bebbd796ed..434c1d7b269d 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -1,4 +1,4 @@ -error: `FileType::is_file()` does not cover all readable file types +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() { @@ -7,7 +7,7 @@ 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()` does not deny all readable file types +error: `!FileType::is_file()` only denys regular files --> $DIR/filetype_is_file.rs:13:8 | LL | if !fs::metadata("foo.txt")?.file_type().is_file() { @@ -15,7 +15,7 @@ LL | if !fs::metadata("foo.txt")?.file_type().is_file() { | = help: use `FileType::is_dir()` instead -error: `FileType::is_file()` does not cover all readable file types +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) { From 1018b78f41af023f92d48912eb03438075a73bd5 Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 8 Jan 2020 16:40:34 +0800 Subject: [PATCH 10/13] Update clippy_lints/src/methods/mod.rs Co-Authored-By: Philipp Krones --- clippy_lints/src/methods/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 2798f6f74abb..25fad58f7948 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3278,7 +3278,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: & if op == hir::UnNot; then { lint_unary = "!"; - verb = "denys"; + verb = "denies"; help_unary = ""; span = parent; } else { From 77c48ca34107d39ac82cd2d0032c49aac85e773b Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Wed, 8 Jan 2020 16:50:37 +0800 Subject: [PATCH 11/13] Fix grammar error. --- clippy_lints/src/methods/mod.rs | 8 ++++---- tests/ui/filetype_is_file.stderr | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 25fad58f7948..ddadf02238a4 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3268,7 +3268,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: & return; } - let span: &hir::Expr<'_>; + let span: Span; let verb: &str; let lint_unary: &str; let help_unary: &str; @@ -3280,15 +3280,15 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: & lint_unary = "!"; verb = "denies"; help_unary = ""; - span = parent; + span = parent.span; } else { lint_unary = ""; verb = "covers"; help_unary = "!"; - span = expr; + span = expr.span; } } let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb); let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary); - span_help_and_lint(cx, FILETYPE_IS_FILE, span.span, &lint_msg, &help_msg); + span_help_and_lint(cx, FILETYPE_IS_FILE, span, &lint_msg, &help_msg); } diff --git a/tests/ui/filetype_is_file.stderr b/tests/ui/filetype_is_file.stderr index 434c1d7b269d..cd1e3ac37fe8 100644 --- a/tests/ui/filetype_is_file.stderr +++ b/tests/ui/filetype_is_file.stderr @@ -7,7 +7,7 @@ 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 denys regular files +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() { From 2b477f361eda786c64f7cdc19c5034fc3269dacc Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Wed, 8 Jan 2020 16:56:28 +0800 Subject: [PATCH 12/13] Update lints again. --- clippy_lints/src/methods/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index ddadf02238a4..f083543d68d4 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3275,7 +3275,7 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: & if_chain! { if let Some(parent) = get_parent_expr(cx, expr); if let hir::ExprKind::Unary(op, _) = parent.kind; - if op == hir::UnNot; + if op == hir::UnOp::UnNot; then { lint_unary = "!"; verb = "denies"; From bba468887bb3c20ff8e38a61bb0f2222836cb451 Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Sat, 11 Jan 2020 11:57:49 +0800 Subject: [PATCH 13/13] Pull master, rebase, and update_lints again. --- README.md | 2 +- src/lintlist/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4de256e9e72f..7b1d14e9afca 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 346 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 347 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 8554de78d859..9cad1ac786af 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 346] = [ +pub const ALL_LINTS: [Lint; 347] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness",