Skip to content

Commit f5eef61

Browse files
committed
Change lint message.
1 parent 9255f5b commit f5eef61

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

clippy_lints/src/methods/mod.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -3213,18 +3213,27 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &
32133213
return;
32143214
}
32153215

3216+
let span: &hir::Expr<'_>;
3217+
let verb: &str;
3218+
let lint_unary: &str;
3219+
let help_unary: &str;
32163220
if_chain! {
32173221
if let Some(parent) = get_parent_expr(cx, expr);
32183222
if let hir::ExprKind::Unary(op, _) = parent.kind;
32193223
if op == hir::UnNot;
32203224
then {
3221-
let lint_msg = "`!FileType::is_file()` does not deny all readable file types";
3222-
let help_msg = "use `FileType::is_dir()` instead";
3223-
span_help_and_lint(cx, FILETYPE_IS_FILE, parent.span, lint_msg, help_msg);
3225+
lint_unary = "!";
3226+
verb = "denys";
3227+
help_unary = "";
3228+
span = parent;
32243229
} else {
3225-
let lint_msg = "`FileType::is_file()` does not cover all readable file types";
3226-
let help_msg = "use `!FileType::is_dir()` instead";
3227-
span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg);
3230+
lint_unary = "";
3231+
verb = "covers";
3232+
help_unary = "!";
3233+
span = expr;
32283234
}
32293235
}
3236+
let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
3237+
let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
3238+
span_help_and_lint(cx, FILETYPE_IS_FILE, span.span, &lint_msg, &help_msg);
32303239
}

tests/ui/filetype_is_file.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `FileType::is_file()` does not cover all readable file types
1+
error: `FileType::is_file()` only covers regular files
22
--> $DIR/filetype_is_file.rs:8:8
33
|
44
LL | if fs::metadata("foo.txt")?.file_type().is_file() {
@@ -7,15 +7,15 @@ LL | if fs::metadata("foo.txt")?.file_type().is_file() {
77
= note: `-D clippy::filetype-is-file` implied by `-D warnings`
88
= help: use `!FileType::is_dir()` instead
99

10-
error: `!FileType::is_file()` does not deny all readable file types
10+
error: `!FileType::is_file()` only denys regular files
1111
--> $DIR/filetype_is_file.rs:13:8
1212
|
1313
LL | if !fs::metadata("foo.txt")?.file_type().is_file() {
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: use `FileType::is_dir()` instead
1717

18-
error: `FileType::is_file()` does not cover all readable file types
18+
error: `FileType::is_file()` only covers regular files
1919
--> $DIR/filetype_is_file.rs:18:9
2020
|
2121
LL | if !fs::metadata("foo.txt")?.file_type().is_file().bitor(true) {

0 commit comments

Comments
 (0)