Skip to content

Commit 8d3cc6b

Browse files
committed
Change lint message.
1 parent 2909bc3 commit 8d3cc6b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,18 +3268,27 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &
32683268
return;
32693269
}
32703270

3271+
let span: &hir::Expr<'_>;
3272+
let verb: &str;
3273+
let lint_unary: &str;
3274+
let help_unary: &str;
32713275
if_chain! {
32723276
if let Some(parent) = get_parent_expr(cx, expr);
32733277
if let hir::ExprKind::Unary(op, _) = parent.kind;
32743278
if op == hir::UnNot;
32753279
then {
3276-
let lint_msg = "`!FileType::is_file()` does not deny all readable file types";
3277-
let help_msg = "use `FileType::is_dir()` instead";
3278-
span_help_and_lint(cx, FILETYPE_IS_FILE, parent.span, lint_msg, help_msg);
3280+
lint_unary = "!";
3281+
verb = "denys";
3282+
help_unary = "";
3283+
span = parent;
32793284
} else {
3280-
let lint_msg = "`FileType::is_file()` does not cover all readable file types";
3281-
let help_msg = "use `!FileType::is_dir()` instead";
3282-
span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg);
3285+
lint_unary = "";
3286+
verb = "covers";
3287+
help_unary = "!";
3288+
span = expr;
32833289
}
32843290
}
3291+
let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
3292+
let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
3293+
span_help_and_lint(cx, FILETYPE_IS_FILE, span.span, &lint_msg, &help_msg);
32853294
}

tests/ui/filetype_is_file.stderr

Lines changed: 3 additions & 3 deletions
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)