@@ -189,15 +189,15 @@ fn gen_trait_body_impl(
189
189
match trait_path. segment ( ) ?. name_ref ( ) ?. text ( ) . as_str ( ) {
190
190
"Debug" => gen_debug_impl ( adt, func, annotated_name) ,
191
191
"Default" => gen_default_impl ( adt, func) ,
192
- _ => Some ( ( ) ) ,
192
+ _ => None ,
193
193
}
194
194
}
195
195
196
196
/// Generate a `Debug` impl based on the fields and members of the target type.
197
197
fn gen_debug_impl ( adt : & ast:: Adt , func : & ast:: Fn , annotated_name : & ast:: Name ) -> Option < ( ) > {
198
198
match adt {
199
199
// `Debug` cannot be derived for unions, so no default impl can be provided.
200
- ast:: Adt :: Union ( _) => Some ( ( ) ) ,
200
+ ast:: Adt :: Union ( _) => None ,
201
201
202
202
// => match self { Self::Variant => write!(f, "Variant") }
203
203
ast:: Adt :: Enum ( enum_) => {
@@ -279,11 +279,17 @@ fn gen_debug_impl(adt: &ast::Adt, func: &ast::Fn, annotated_name: &ast::Name) ->
279
279
280
280
/// Generate a `Debug` impl based on the fields and members of the target type.
281
281
fn gen_default_impl ( adt : & ast:: Adt , func : & ast:: Fn ) -> Option < ( ) > {
282
- return match adt {
282
+ fn gen_default_call ( ) -> ast:: Expr {
283
+ let trait_name = make:: ext:: ident_path ( "Default" ) ;
284
+ let method_name = make:: ext:: ident_path ( "default" ) ;
285
+ let fn_name = make:: expr_path ( make:: path_concat ( trait_name, method_name) ) ;
286
+ make:: expr_call ( fn_name, make:: arg_list ( None ) )
287
+ }
288
+ match adt {
283
289
// `Debug` cannot be derived for unions, so no default impl can be provided.
284
- ast:: Adt :: Union ( _) => Some ( ( ) ) ,
290
+ ast:: Adt :: Union ( _) => None ,
285
291
// Deriving `Debug` for enums is not stable yet.
286
- ast:: Adt :: Enum ( _) => Some ( ( ) ) ,
292
+ ast:: Adt :: Enum ( _) => None ,
287
293
ast:: Adt :: Struct ( strukt) => {
288
294
let expr = match strukt. field_list ( ) {
289
295
Some ( ast:: FieldList :: RecordFieldList ( field_list) ) => {
@@ -311,15 +317,8 @@ fn gen_default_impl(adt: &ast::Adt, func: &ast::Fn) -> Option<()> {
311
317
} ;
312
318
let body = make:: block_expr ( None , Some ( expr) ) . indent ( ast:: edit:: IndentLevel ( 1 ) ) ;
313
319
ted:: replace ( func. body ( ) ?. syntax ( ) , body. clone_for_update ( ) . syntax ( ) ) ;
314
- return Some ( ( ) ) ;
320
+ Some ( ( ) )
315
321
}
316
- } ;
317
-
318
- fn gen_default_call ( ) -> ast:: Expr {
319
- let trait_name = make:: ext:: ident_path ( "Default" ) ;
320
- let method_name = make:: ext:: ident_path ( "default" ) ;
321
- let fn_name = make:: expr_path ( make:: path_concat ( trait_name, method_name) ) ;
322
- make:: expr_call ( fn_name, make:: arg_list ( None ) )
323
322
}
324
323
}
325
324
fn update_attribute (
0 commit comments