@@ -23,12 +23,11 @@ use syntax::{
2323 ast:: {
2424 self , HasArgList , HasAttrs , HasGenericParams , HasName , HasTypeBounds , Whitespace ,
2525 edit:: { AstNodeEdit , IndentLevel } ,
26- edit_in_place:: { AttrsOwnerEdit , Removable } ,
26+ edit_in_place:: AttrsOwnerEdit ,
2727 make,
2828 syntax_factory:: SyntaxFactory ,
2929 } ,
30- syntax_editor:: SyntaxEditor ,
31- ted,
30+ syntax_editor:: { Removable , SyntaxEditor } ,
3231} ;
3332
3433use crate :: {
@@ -207,7 +206,7 @@ pub fn add_trait_assoc_items_to_impl(
207206 stdx:: never!( "formatted `AssocItem` could not be cast back to `AssocItem`" ) ;
208207 }
209208 }
210- original_item. clone_for_update ( )
209+ original_item
211210 }
212211 . reset_indent ( ) ;
213212
@@ -221,31 +220,37 @@ pub fn add_trait_assoc_items_to_impl(
221220 cloned_item. remove_attrs_and_docs ( ) ;
222221 cloned_item
223222 } )
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) )
244249 }
245- _ => { }
246250 }
247- AstNodeEdit :: indent ( & item, new_indent_level )
251+ item => Some ( item ) ,
248252 } )
253+ . map ( |item| AstNodeEdit :: indent ( & item, new_indent_level) )
249254 . collect ( )
250255}
251256
0 commit comments