@@ -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
@@ -214,7 +213,7 @@ enum Foo {
214213fn bar(foo: Foo) {
215214 match foo {
216215 Foo::A(_) => false,
217- Foo::B{ y, z } => true,
216+ Foo::B{ y, z } => true,
218217 };
219218}
220219"# ,
@@ -275,7 +274,7 @@ struct Bar {
275274}
276275
277276fn foo(bar: Bar) {
278- let Bar { y, z } = bar;
277+ let Bar { y, z } = bar;
279278}
280279"# ,
281280 ) ;
@@ -379,7 +378,7 @@ macro_rules! position {
379378position!(usize);
380379
381380fn macro_call(pos: Pos) {
382- let Pos { x, y } = pos;
381+ let Pos { x, y } = pos;
383382}
384383"# ,
385384 ) ;
@@ -423,7 +422,7 @@ enum_gen!(usize);
423422fn macro_call(foo: Foo) {
424423 match foo {
425424 Foo::A(_) => false,
426- Foo::B{ x, y } => true,
425+ Foo::B{ x, y } => true,
427426 }
428427}
429428"# ,
0 commit comments