diff options
| author | xiongmao86 <xiongmao86dev@sina.com> | 2020-01-07 16:33:33 +0800 |
|---|---|---|
| committer | xiongmao86 <xiongmao86dev@sina.com> | 2020-01-12 19:54:17 +0800 |
| commit | 8d3cc6b8a970efa656a446bbd040d30e5c248501 (patch) | |
| tree | 338870aac164535f3202d64482837a0852cea514 | |
| parent | 2909bc372fb51fe21be59aca3950eca9ad1514d8 (diff) | |
| download | rust-8d3cc6b8a970efa656a446bbd040d30e5c248501.tar.gz rust-8d3cc6b8a970efa656a446bbd040d30e5c248501.zip | |
Change lint message.
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 21 | ||||
| -rw-r--r-- | 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 4c372e019dc..2798f6f74ab 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 08bebbd796e..434c1d7b269 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) { |
