@@ -20,8 +20,8 @@ declare_lint! {
20
20
/// }
21
21
///
22
22
/// #[deny(default_could_be_derived)]
23
- /// impl Default for Foo {
24
- /// fn default() -> Foo {
23
+ /// impl Default for A {
24
+ /// fn default() -> A {
25
25
/// A {
26
26
/// b: None,
27
27
/// }
@@ -59,12 +59,14 @@ declare_lint! {
59
59
}
60
60
61
61
declare_lint ! {
62
- /// The `default_could_be_derived` lint checks for manual `impl` blocks
63
- /// of the `Default` trait that could have been derived.
62
+ /// The `manual_default_for_type_with_default_fields` lint checks for
63
+ /// manual `impl` blocks of the `Default` trait of types with default
64
+ /// field values.
64
65
///
65
66
/// ### Example
66
67
///
67
68
/// ```rust,compile_fail
69
+ /// #![allow(default_field_values)]
68
70
/// struct Foo {
69
71
/// x: i32 = 101,
70
72
/// }
@@ -114,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
114
116
kind :
115
117
hir:: ItemKind :: Struct ( hir:: VariantData :: Struct { fields, recovered : _ } , _generics) ,
116
118
..
117
- } ) ) => {
119
+ } ) ) if cx . tcx . features ( ) . default_field_values ( ) => {
118
120
let fields_with_default_value: Vec < _ > =
119
121
fields. iter ( ) . filter_map ( |f| f. default ) . collect ( ) ;
120
122
let fields_with_default_impl: Vec < _ > = fields
@@ -133,6 +135,10 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
133
135
_ => None ,
134
136
} )
135
137
. collect ( ) ;
138
+ // FIXME: look at the `Default::default()` implementation and call check_expr and
139
+ // check_const_expr on every field. If all are either of those, then we suggest
140
+ // adding a default field value for the const-able ones and deriving if the feature
141
+ // is enabled.
136
142
if !fields_with_default_value. is_empty ( )
137
143
&& fields. len ( )
138
144
== fields_with_default_value. len ( ) + fields_with_default_impl. len ( )
0 commit comments