Skip to content

Commit f6cf303

Browse files
authored
Merge pull request #20730 from A4-Tacks/migrate-expand-rest-pat
Migrate `expand_record_rest_pattern` assist to use `SyntaxEditor`
2 parents 7804a2d + 258776b commit f6cf303

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

crates/ide-assists/src/handlers/expand_rest_pattern.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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
// ```
3030
fn 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 {
214213
fn 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
277276
fn 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 {
379378
position!(usize);
380379
381380
fn 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);
423422
fn 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
"#,

crates/ide-assists/src/tests/generated.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ fn foo(bar: Bar) {
10351035
struct Bar { y: Y, z: Z }
10361036
10371037
fn foo(bar: Bar) {
1038-
let Bar { y, z } = bar;
1038+
let Bar { y, z } = bar;
10391039
}
10401040
"#####,
10411041
)

0 commit comments

Comments
 (0)