1
1
use clippy_utils:: diagnostics:: span_lint_and_help;
2
- use clippy_utils:: path_def_id ;
2
+ use clippy_utils:: is_trait_item ;
3
3
use clippy_utils:: source:: snippet;
4
4
use rustc_hir:: { ExprKind , StructTailExpr } ;
5
5
use rustc_lint:: { LateLintPass , LintContext } ;
@@ -50,7 +50,7 @@ declare_clippy_lint! {
50
50
#[ clippy:: version = "1.87.0" ]
51
51
pub STRUCT_FIELDS_REST_DEFAULT ,
52
52
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"
54
54
}
55
55
56
56
declare_lint_pass ! ( StructFieldsDefault => [ STRUCT_FIELDS_REST_DEFAULT ] ) ;
@@ -60,19 +60,18 @@ impl<'tcx> LateLintPass<'tcx> for StructFieldsDefault {
60
60
if !expr. span . in_external_macro ( cx. sess ( ) . source_map ( ) )
61
61
&& let ExprKind :: Struct ( _, _, StructTailExpr :: Base ( base) ) = & expr. kind
62
62
&& 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 )
65
64
{
66
65
span_lint_and_help (
67
66
cx,
68
67
STRUCT_FIELDS_REST_DEFAULT ,
69
68
base. span ,
70
69
format ! (
71
70
"should not use `..{}` to omit rest of struct field initialization" ,
72
- snippet( cx, base. span, ".. " )
71
+ snippet( cx, base. span, "" )
73
72
) ,
74
73
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()` " ,
76
75
) ;
77
76
}
78
77
}
0 commit comments