Skip to content

Commit 7b8912c

Browse files
committed
Fix struct_fields_rest_default helping message
1 parent 554f903 commit 7b8912c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

clippy_lints/src/struct_fields_rest_default.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::path_def_id;
2+
use clippy_utils::is_trait_item;
33
use clippy_utils::source::snippet;
44
use rustc_hir::{ExprKind, StructTailExpr};
55
use rustc_lint::{LateLintPass, LintContext};
@@ -50,7 +50,7 @@ declare_clippy_lint! {
5050
#[clippy::version = "1.87.0"]
5151
pub STRUCT_FIELDS_REST_DEFAULT,
5252
restriction,
53-
"should not use `..Default::default()` to omit rest of struct field initialization"
53+
"should not use `..*::default()` pattern to omit rest of struct field initialization"
5454
}
5555

5656
declare_lint_pass!(StructFieldsDefault => [STRUCT_FIELDS_REST_DEFAULT]);
@@ -60,19 +60,18 @@ impl<'tcx> LateLintPass<'tcx> for StructFieldsDefault {
6060
if !expr.span.in_external_macro(cx.sess().source_map())
6161
&& let ExprKind::Struct(_, _, StructTailExpr::Base(base)) = &expr.kind
6262
&& let ExprKind::Call(func, _) = base.kind
63-
&& let Some(did) = path_def_id(cx, func)
64-
&& cx.tcx.is_diagnostic_item(sym::default_fn, did)
63+
&& is_trait_item(cx, func, sym::Default)
6564
{
6665
span_lint_and_help(
6766
cx,
6867
STRUCT_FIELDS_REST_DEFAULT,
6968
base.span,
7069
format!(
7170
"should not use `..{}` to omit rest of struct field initialization",
72-
snippet(cx, base.span, "..")
71+
snippet(cx, base.span, "")
7372
),
7473
Some(expr.span),
75-
"each field's initial value should be explicitly specified",
74+
"explicitly specify all fields or use other base value instead of `..*::default()`",
7675
);
7776
}
7877
}

tests/ui/struct_fields_rest_default.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: should not use `..Default::default()` to omit rest of struct field initia
44
LL | ..Default::default()
55
| ^^^^^^^^^^^^^^^^^^
66
|
7-
help: each field's initial value should be explicitly specified
7+
help: explicitly specify all fields or use other base value instead of `..*::default()`
88
--> tests/ui/struct_fields_rest_default.rs:20:13
99
|
1010
LL | let _ = Foo {
@@ -23,7 +23,7 @@ error: should not use `..Foo::default()` to omit rest of struct field initializa
2323
LL | ..Foo::default()
2424
| ^^^^^^^^^^^^^^
2525
|
26-
help: each field's initial value should be explicitly specified
26+
help: explicitly specify all fields or use other base value instead of `..*::default()`
2727
--> tests/ui/struct_fields_rest_default.rs:27:13
2828
|
2929
LL | let _ = Foo {

0 commit comments

Comments
 (0)