@@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, Assists};
24
24
// struct Bar { y: Y, z: Z }
25
25
//
26
26
// fn foo(bar: Bar) {
27
- // let Bar { y, z } = bar;
27
+ // let Bar { y, z } = bar;
28
28
// }
29
29
// ```
30
30
fn expand_record_rest_pattern (
@@ -53,18 +53,17 @@ fn expand_record_rest_pattern(
53
53
|builder| {
54
54
let make = SyntaxFactory :: with_mappings ( ) ;
55
55
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 (
59
58
make. ident_pat (
60
59
false ,
61
60
false ,
62
61
make. name ( & f. name ( ctx. sema . db ) . display_no_db ( edition) . to_smolstr ( ) ) ,
63
62
)
64
63
. 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 ) ;
68
67
69
68
editor. replace ( old_field_list. syntax ( ) , new_field_list. syntax ( ) ) ;
70
69
@@ -211,7 +210,7 @@ enum Foo {
211
210
fn bar(foo: Foo) {
212
211
match foo {
213
212
Foo::A(_) => false,
214
- Foo::B{ y, z } => true,
213
+ Foo::B{ y, z } => true,
215
214
};
216
215
}
217
216
"# ,
@@ -272,7 +271,7 @@ struct Bar {
272
271
}
273
272
274
273
fn foo(bar: Bar) {
275
- let Bar { y, z } = bar;
274
+ let Bar { y, z } = bar;
276
275
}
277
276
"# ,
278
277
) ;
@@ -376,7 +375,7 @@ macro_rules! position {
376
375
position!(usize);
377
376
378
377
fn macro_call(pos: Pos) {
379
- let Pos { x, y } = pos;
378
+ let Pos { x, y } = pos;
380
379
}
381
380
"# ,
382
381
) ;
@@ -420,7 +419,7 @@ enum_gen!(usize);
420
419
fn macro_call(foo: Foo) {
421
420
match foo {
422
421
Foo::A(_) => false,
423
- Foo::B{ x, y } => true,
422
+ Foo::B{ x, y } => true,
424
423
}
425
424
}
426
425
"# ,
0 commit comments