@@ -20,8 +20,8 @@ declare_lint! {
2020 /// }
2121 ///
2222 /// #[deny(default_could_be_derived)]
23- /// impl Default for Foo {
24- /// fn default() -> Foo {
23+ /// impl Default for A {
24+ /// fn default() -> A {
2525 /// A {
2626 /// b: None,
2727 /// }
@@ -59,12 +59,14 @@ declare_lint! {
5959}
6060
6161declare_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.
6465 ///
6566 /// ### Example
6667 ///
6768 /// ```rust,compile_fail
69+ /// #![feature(default_field_values)]
6870 /// struct Foo {
6971 /// x: i32 = 101,
7072 /// }
@@ -114,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
114116 kind :
115117 hir:: ItemKind :: Struct ( hir:: VariantData :: Struct { fields, recovered : _ } , _generics) ,
116118 ..
117- } ) ) => {
119+ } ) ) if cx . tcx . features ( ) . default_field_values ( ) => {
118120 let fields_with_default_value: Vec < _ > =
119121 fields. iter ( ) . filter_map ( |f| f. default ) . collect ( ) ;
120122 let fields_with_default_impl: Vec < _ > = fields
@@ -133,6 +135,10 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
133135 _ => None ,
134136 } )
135137 . 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.
136142 if !fields_with_default_value. is_empty ( )
137143 && fields. len ( )
138144 == fields_with_default_value. len ( ) + fields_with_default_impl. len ( )
0 commit comments