Skip to content

Commit 416ff1c

Browse files
committed
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) {} ```
1 parent 370c5c9 commit 416ff1c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ fn process_struct_name_reference(
202202
.record_pat_field_list()?
203203
.fields()
204204
.filter_map(|pat| pat.pat())
205+
.chain(record_struct_pat.record_pat_field_list()?
206+
.rest_pat()
207+
.map(Into::into))
205208
)
206209
.to_string()
207210
);
@@ -346,6 +349,37 @@ impl A {
346349
);
347350
}
348351

352+
#[test]
353+
fn convert_struct_and_rest_pat() {
354+
check_assist(
355+
convert_named_struct_to_tuple_struct,
356+
r#"
357+
struct Inner;
358+
struct A$0 { inner: Inner }
359+
fn foo(A { .. }: A) {}
360+
"#,
361+
r#"
362+
struct Inner;
363+
struct A(Inner);
364+
fn foo(A(..): A) {}
365+
"#,
366+
);
367+
368+
check_assist(
369+
convert_named_struct_to_tuple_struct,
370+
r#"
371+
struct Inner;
372+
struct A$0 { inner: Inner, extra: Inner }
373+
fn foo(A { inner, .. }: A) {}
374+
"#,
375+
r#"
376+
struct Inner;
377+
struct A(Inner, Inner);
378+
fn foo(A(inner, ..): A) {}
379+
"#,
380+
);
381+
}
382+
349383
#[test]
350384
fn convert_simple_struct_cursor_on_visibility_keyword() {
351385
check_assist(

0 commit comments

Comments
 (0)