mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-25 11:17:13 +00:00
Merge pull request #20730 from A4-Tacks/migrate-expand-rest-pat
Migrate `expand_record_rest_pattern` assist to use `SyntaxEditor`
This commit is contained in:
commit
f6cf3035c3
@ -24,7 +24,7 @@ use crate::{AssistContext, AssistId, Assists};
|
|||||||
// struct Bar { y: Y, z: Z }
|
// struct Bar { y: Y, z: Z }
|
||||||
//
|
//
|
||||||
// fn foo(bar: Bar) {
|
// fn foo(bar: Bar) {
|
||||||
// let Bar { y, z } = bar;
|
// let Bar { y, z } = bar;
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
fn expand_record_rest_pattern(
|
fn expand_record_rest_pattern(
|
||||||
@ -53,18 +53,17 @@ fn expand_record_rest_pattern(
|
|||||||
|builder| {
|
|builder| {
|
||||||
let make = SyntaxFactory::with_mappings();
|
let make = SyntaxFactory::with_mappings();
|
||||||
let mut editor = builder.make_editor(rest_pat.syntax());
|
let mut editor = builder.make_editor(rest_pat.syntax());
|
||||||
let new_field_list = make.record_pat_field_list(old_field_list.fields(), None);
|
let new_fields = old_field_list.fields().chain(missing_fields.iter().map(|(f, _)| {
|
||||||
for (f, _) in missing_fields.iter() {
|
make.record_pat_field_shorthand(
|
||||||
let field = make.record_pat_field_shorthand(
|
|
||||||
make.ident_pat(
|
make.ident_pat(
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
make.name(&f.name(ctx.sema.db).display_no_db(edition).to_smolstr()),
|
make.name(&f.name(ctx.sema.db).display_no_db(edition).to_smolstr()),
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
)
|
||||||
new_field_list.add_field(field);
|
}));
|
||||||
}
|
let new_field_list = make.record_pat_field_list(new_fields, None);
|
||||||
|
|
||||||
editor.replace(old_field_list.syntax(), new_field_list.syntax());
|
editor.replace(old_field_list.syntax(), new_field_list.syntax());
|
||||||
|
|
||||||
@ -214,7 +213,7 @@ enum Foo {
|
|||||||
fn bar(foo: Foo) {
|
fn bar(foo: Foo) {
|
||||||
match foo {
|
match foo {
|
||||||
Foo::A(_) => false,
|
Foo::A(_) => false,
|
||||||
Foo::B{ y, z } => true,
|
Foo::B{ y, z } => true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
@ -275,7 +274,7 @@ struct Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn foo(bar: Bar) {
|
fn foo(bar: Bar) {
|
||||||
let Bar { y, z } = bar;
|
let Bar { y, z } = bar;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
@ -379,7 +378,7 @@ macro_rules! position {
|
|||||||
position!(usize);
|
position!(usize);
|
||||||
|
|
||||||
fn macro_call(pos: Pos) {
|
fn macro_call(pos: Pos) {
|
||||||
let Pos { x, y } = pos;
|
let Pos { x, y } = pos;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
@ -423,7 +422,7 @@ enum_gen!(usize);
|
|||||||
fn macro_call(foo: Foo) {
|
fn macro_call(foo: Foo) {
|
||||||
match foo {
|
match foo {
|
||||||
Foo::A(_) => false,
|
Foo::A(_) => false,
|
||||||
Foo::B{ x, y } => true,
|
Foo::B{ x, y } => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
@ -1035,7 +1035,7 @@ fn foo(bar: Bar) {
|
|||||||
struct Bar { y: Y, z: Z }
|
struct Bar { y: Y, z: Z }
|
||||||
|
|
||||||
fn foo(bar: Bar) {
|
fn foo(bar: Bar) {
|
||||||
let Bar { y, z } = bar;
|
let Bar { y, z } = bar;
|
||||||
}
|
}
|
||||||
"#####,
|
"#####,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user