Unnamed repository; edit this file 'description' to name the repository.
Fix missing RestPat for convert_named_struct_to_tuple_struct
Example --- ```rust struct Inner; struct A$0 { inner: Inner } fn foo(A { .. }: A) {} ``` **Before this PR**: ```rust struct Inner; struct A(Inner); fn foo(A(): A) {} ``` **After this PR**: ```rust struct Inner; struct A(Inner); fn foo(A(..): A) {} ```
A4-Tacks 6 months ago
parent 370c5c9 · commit 416ff1c
-rw-r--r--crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs b/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs
index 8d27574eb2..0847719d69 100644
--- a/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs
+++ b/crates/ide-assists/src/handlers/convert_named_struct_to_tuple_struct.rs
@@ -202,6 +202,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()
);
@@ -347,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(
convert_named_struct_to_tuple_struct,