From 416ff1c2c102c01cb8ca3e2059ba913b40288d3e Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Mon, 20 Oct 2025 15:04:51 +0800 Subject: [PATCH 1/2] 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) {} ``` --- .../convert_named_struct_to_tuple_struct.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 8d27574eb2ca..0847719d6922 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() ); @@ -346,6 +349,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( From 9fb0cd76f716c0f9cb8e7d5696c0c3139d468af0 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Tue, 21 Oct 2025 11:27:50 +0800 Subject: [PATCH 2/2] Add a FIXME for unordered fields --- .../src/handlers/convert_named_struct_to_tuple_struct.rs | 1 + 1 file changed, 1 insertion(+) 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 0847719d6922..e518c39dabc2 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 @@ -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 {