@@ -23,12 +23,11 @@ use syntax::{
23
23
ast:: {
24
24
self , HasArgList , HasAttrs , HasGenericParams , HasName , HasTypeBounds , Whitespace ,
25
25
edit:: { AstNodeEdit , IndentLevel } ,
26
- edit_in_place:: { AttrsOwnerEdit , Removable } ,
26
+ edit_in_place:: AttrsOwnerEdit ,
27
27
make,
28
28
syntax_factory:: SyntaxFactory ,
29
29
} ,
30
- syntax_editor:: SyntaxEditor ,
31
- ted,
30
+ syntax_editor:: { Removable , SyntaxEditor } ,
32
31
} ;
33
32
34
33
use crate :: {
@@ -207,7 +206,7 @@ pub fn add_trait_assoc_items_to_impl(
207
206
stdx:: never!( "formatted `AssocItem` could not be cast back to `AssocItem`" ) ;
208
207
}
209
208
}
210
- original_item. clone_for_update ( )
209
+ original_item
211
210
}
212
211
. reset_indent ( ) ;
213
212
@@ -221,31 +220,37 @@ pub fn add_trait_assoc_items_to_impl(
221
220
cloned_item. remove_attrs_and_docs ( ) ;
222
221
cloned_item
223
222
} )
224
- . map ( |item| {
225
- match & item {
226
- ast:: AssocItem :: Fn ( fn_) if fn_. body ( ) . is_none ( ) => {
227
- let body = AstNodeEdit :: indent (
228
- & make:: block_expr (
229
- None ,
230
- Some ( match config. expr_fill_default {
231
- ExprFillDefaultMode :: Todo => make:: ext:: expr_todo ( ) ,
232
- ExprFillDefaultMode :: Underscore => make:: ext:: expr_underscore ( ) ,
233
- ExprFillDefaultMode :: Default => make:: ext:: expr_todo ( ) ,
234
- } ) ,
235
- ) ,
236
- IndentLevel :: single ( ) ,
237
- ) ;
238
- ted:: replace ( fn_. get_or_create_body ( ) . syntax ( ) , body. syntax ( ) ) ;
239
- }
240
- ast:: AssocItem :: TypeAlias ( type_alias) => {
241
- if let Some ( type_bound_list) = type_alias. type_bound_list ( ) {
242
- type_bound_list. remove ( )
243
- }
223
+ . filter_map ( |item| match item {
224
+ ast:: AssocItem :: Fn ( fn_) if fn_. body ( ) . is_none ( ) => {
225
+ let fn_ = fn_. clone_subtree ( ) ;
226
+ let new_body = & make:: block_expr (
227
+ None ,
228
+ Some ( match config. expr_fill_default {
229
+ ExprFillDefaultMode :: Todo => make:: ext:: expr_todo ( ) ,
230
+ ExprFillDefaultMode :: Underscore => make:: ext:: expr_underscore ( ) ,
231
+ ExprFillDefaultMode :: Default => make:: ext:: expr_todo ( ) ,
232
+ } ) ,
233
+ ) ;
234
+ let new_body = AstNodeEdit :: indent ( new_body, IndentLevel :: single ( ) ) ;
235
+ let mut fn_editor = SyntaxEditor :: new ( fn_. syntax ( ) . clone ( ) ) ;
236
+ fn_. replace_or_insert_body ( & mut fn_editor, new_body) ;
237
+ let new_fn_ = fn_editor. finish ( ) . new_root ( ) . clone ( ) ;
238
+ ast:: AssocItem :: cast ( new_fn_)
239
+ }
240
+ ast:: AssocItem :: TypeAlias ( type_alias) => {
241
+ let type_alias = type_alias. clone_subtree ( ) ;
242
+ if let Some ( type_bound_list) = type_alias. type_bound_list ( ) {
243
+ let mut type_alias_editor = SyntaxEditor :: new ( type_alias. syntax ( ) . clone ( ) ) ;
244
+ type_bound_list. remove ( & mut type_alias_editor) ;
245
+ let type_alias = type_alias_editor. finish ( ) . new_root ( ) . clone ( ) ;
246
+ ast:: AssocItem :: cast ( type_alias)
247
+ } else {
248
+ Some ( ast:: AssocItem :: TypeAlias ( type_alias) )
244
249
}
245
- _ => { }
246
250
}
247
- AstNodeEdit :: indent ( & item, new_indent_level )
251
+ item => Some ( item ) ,
248
252
} )
253
+ . map ( |item| AstNodeEdit :: indent ( & item, new_indent_level) )
249
254
. collect ( )
250
255
}
251
256
0 commit comments