Merge pull request #20872 from A4-Tacks/conv-named-to-tuple-rest-pat
Fix missing RestPat for convert_named_struct_to_tuple_struct
This commit is contained in:
commit
34af63109f
1 changed files with 35 additions and 0 deletions
|
|
@ -187,6 +187,7 @@ fn process_struct_name_reference(
|
|||
return None;
|
||||
}
|
||||
|
||||
// FIXME: Processing RecordPat and RecordExpr for unordered fields, and insert RestPat
|
||||
let parent = full_path.syntax().parent()?;
|
||||
match_ast! {
|
||||
match parent {
|
||||
|
|
@ -202,6 +203,9 @@ fn process_struct_name_reference(
|
|||
.record_pat_field_list()?
|
||||
.fields()
|
||||
.filter_map(|pat| pat.pat())
|
||||
.chain(record_struct_pat.record_pat_field_list()?
|
||||
.rest_pat()
|
||||
.map(Into::into))
|
||||
)
|
||||
.to_string()
|
||||
);
|
||||
|
|
@ -346,6 +350,37 @@ impl A {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_struct_and_rest_pat() {
|
||||
check_assist(
|
||||
convert_named_struct_to_tuple_struct,
|
||||
r#"
|
||||
struct Inner;
|
||||
struct A$0 { inner: Inner }
|
||||
fn foo(A { .. }: A) {}
|
||||
"#,
|
||||
r#"
|
||||
struct Inner;
|
||||
struct A(Inner);
|
||||
fn foo(A(..): A) {}
|
||||
"#,
|
||||
);
|
||||
|
||||
check_assist(
|
||||
convert_named_struct_to_tuple_struct,
|
||||
r#"
|
||||
struct Inner;
|
||||
struct A$0 { inner: Inner, extra: Inner }
|
||||
fn foo(A { inner, .. }: A) {}
|
||||
"#,
|
||||
r#"
|
||||
struct Inner;
|
||||
struct A(Inner, Inner);
|
||||
fn foo(A(inner, ..): A) {}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn convert_simple_struct_cursor_on_visibility_keyword() {
|
||||
check_assist(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue