@@ -1276,32 +1276,26 @@ fn node_to_insert_after(body: &FunctionBody, anchor: Anchor) -> Option<SyntaxNod
1276
1276
last_ancestor
1277
1277
}
1278
1278
1279
- fn find_non_trait_impl ( trait_impl : & SyntaxNode ) -> Option < SyntaxNode > {
1280
- let impl_type = Some ( impl_type_name ( trait_impl) ?) ;
1279
+ fn find_non_trait_impl ( trait_impl : & SyntaxNode ) -> Option < ast:: Impl > {
1280
+ let as_impl = ast:: Impl :: cast ( trait_impl. clone ( ) ) ?;
1281
+ let impl_type = Some ( impl_type_name ( & as_impl) ?) ;
1281
1282
1282
- let mut sibblings = trait_impl. parent ( ) ?. children ( ) ;
1283
- sibblings. find ( |s| impl_type_name ( s) == impl_type && !is_trait_impl ( s) )
1283
+ let sibblings = trait_impl. parent ( ) ?. children ( ) ;
1284
+ sibblings. filter_map ( ast:: Impl :: cast)
1285
+ . find ( |s| impl_type_name ( s) == impl_type && !is_trait_impl ( s) )
1284
1286
}
1285
1287
1286
- fn last_impl_member ( impl_node : & SyntaxNode ) -> Option < SyntaxNode > {
1287
- impl_node. children ( ) . find ( |c| c. kind ( ) == SyntaxKind :: ASSOC_ITEM_LIST ) ?. last_child ( )
1288
+ fn last_impl_member ( impl_node : & ast:: Impl ) -> Option < SyntaxNode > {
1289
+ let last_child = impl_node. assoc_item_list ( ) ?. assoc_items ( ) . last ( ) ?;
1290
+ Some ( last_child. syntax ( ) . clone ( ) )
1288
1291
}
1289
1292
1290
- fn is_trait_impl ( node : & SyntaxNode ) -> bool {
1291
- if !ast:: Impl :: can_cast ( node. kind ( ) ) {
1292
- return false ;
1293
- }
1294
- match ast:: Impl :: cast ( node. clone ( ) ) {
1295
- Some ( c) => c. trait_ ( ) . is_some ( ) ,
1296
- None => false ,
1297
- }
1293
+ fn is_trait_impl ( node : & ast:: Impl ) -> bool {
1294
+ node. trait_ ( ) . is_some ( )
1298
1295
}
1299
1296
1300
- fn impl_type_name ( impl_node : & SyntaxNode ) -> Option < String > {
1301
- if !ast:: Impl :: can_cast ( impl_node. kind ( ) ) {
1302
- return None ;
1303
- }
1304
- Some ( ast:: Impl :: cast ( impl_node. clone ( ) ) ?. self_ty ( ) ?. to_string ( ) )
1297
+ fn impl_type_name ( impl_node : & ast:: Impl ) -> Option < String > {
1298
+ Some ( impl_node. self_ty ( ) ?. to_string ( ) )
1305
1299
}
1306
1300
1307
1301
fn make_call ( ctx : & AssistContext < ' _ > , fun : & Function , indent : IndentLevel ) -> String {
0 commit comments