Skip to content

Commit 4202346

Browse files
committed
Change lint message.
1 parent cea7c79 commit 4202346

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
@@ -3264,18 +3264,27 @@ fn lint_filetype_is_file(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &
32643264
return;
32653265
}
32663266

3267+
let span: &hir::Expr<'_>;
3268+
let verb: &str;
3269+
let lint_unary: &str;
3270+
let help_unary: &str;
32673271
if_chain! {
32683272
if let Some(parent) = get_parent_expr(cx, expr);
32693273
if let hir::ExprKind::Unary(op, _) = parent.kind;
32703274
if op == hir::UnNot;
32713275
then {
3272-
let lint_msg = "`!FileType::is_file()` does not deny all readable file types";
3273-
let help_msg = "use `FileType::is_dir()` instead";
3274-
span_help_and_lint(cx, FILETYPE_IS_FILE, parent.span, lint_msg, help_msg);
3276+
lint_unary = "!";
3277+
verb = "denys";
3278+
help_unary = "";
3279+
span = parent;
32753280
} else {
3276-
let lint_msg = "`FileType::is_file()` does not cover all readable file types";
3277-
let help_msg = "use `!FileType::is_dir()` instead";
3278-
span_help_and_lint(cx, FILETYPE_IS_FILE, expr.span, lint_msg, help_msg);
3281+
lint_unary = "";
3282+
verb = "covers";
3283+
help_unary = "!";
3284+
span = expr;
32793285
}
32803286
}
3287+
let lint_msg = format!("`{}FileType::is_file()` only {} regular files", lint_unary, verb);
3288+
let help_msg = format!("use `{}FileType::is_dir()` instead", help_unary);
3289+
span_help_and_lint(cx, FILETYPE_IS_FILE, span.span, &lint_msg, &help_msg);
32813290
}

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)