@@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, Assists};
2424// struct Bar { y: Y, z: Z }
2525//
2626// fn foo(bar: Bar) {
27- // let Bar { y, z } = bar;
27+ // let Bar { y, z } = bar;
2828// }
2929// ```
3030fn expand_record_rest_pattern (
@@ -53,18 +53,17 @@ fn expand_record_rest_pattern(
5353 |builder| {
5454 let make = SyntaxFactory :: with_mappings ( ) ;
5555 let mut editor = builder. make_editor ( rest_pat. syntax ( ) ) ;
56- let new_field_list = make. record_pat_field_list ( old_field_list. fields ( ) , None ) ;
57- for ( f, _) in missing_fields. iter ( ) {
58- let field = make. record_pat_field_shorthand (
56+ let new_fields = old_field_list. fields ( ) . chain ( missing_fields. iter ( ) . map ( |( f, _) | {
57+ make. record_pat_field_shorthand (
5958 make. ident_pat (
6059 false ,
6160 false ,
6261 make. name ( & f. name ( ctx. sema . db ) . display_no_db ( edition) . to_smolstr ( ) ) ,
6362 )
6463 . into ( ) ,
65- ) ;
66- new_field_list . add_field ( field ) ;
67- }
64+ )
65+ } ) ) ;
66+ let new_field_list = make . record_pat_field_list ( new_fields , None ) ;
6867
6968 editor. replace ( old_field_list. syntax ( ) , new_field_list. syntax ( ) ) ;
7069
@@ -211,7 +210,7 @@ enum Foo {
211210fn bar(foo: Foo) {
212211 match foo {
213212 Foo::A(_) => false,
214- Foo::B{ y, z } => true,
213+ Foo::B{ y, z } => true,
215214 };
216215}
217216"# ,
@@ -272,7 +271,7 @@ struct Bar {
272271}
273272
274273fn foo(bar: Bar) {
275- let Bar { y, z } = bar;
274+ let Bar { y, z } = bar;
276275}
277276"# ,
278277 ) ;
@@ -376,7 +375,7 @@ macro_rules! position {
376375position!(usize);
377376
378377fn macro_call(pos: Pos) {
379- let Pos { x, y } = pos;
378+ let Pos { x, y } = pos;
380379}
381380"# ,
382381 ) ;
@@ -420,7 +419,7 @@ enum_gen!(usize);
420419fn macro_call(foo: Foo) {
421420 match foo {
422421 Foo::A(_) => false,
423- Foo::B{ x, y } => true,
422+ Foo::B{ x, y } => true,
424423 }
425424}
426425"# ,
0 commit comments