Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dcf1d71

Browse files
committedOct 10, 2022
Auto merge of rust-lang#13303 - jplatte:convert-named-struct-to-tuple-struct, r=Veykril
Add convert_named_struct_to_tuple_struct assist Closes rust-lang#11643, since the assist for converting in the other direction is already there (I based most of the implementation and all of the tests on it).
2 parents 79a3f84 + a3d79b5 commit dcf1d71

File tree

4 files changed

+866
-0
lines changed

4 files changed

+866
-0
lines changed
 

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

Lines changed: 822 additions & 0 deletions
Large diffs are not rendered by default.

‎crates/ide-assists/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ mod handlers {
121121
mod convert_iter_for_each_to_for;
122122
mod convert_let_else_to_match;
123123
mod convert_tuple_struct_to_named_struct;
124+
mod convert_named_struct_to_tuple_struct;
124125
mod convert_to_guarded_return;
125126
mod convert_two_arm_bool_match_to_matches_macro;
126127
mod convert_while_to_loop;
@@ -218,6 +219,7 @@ mod handlers {
218219
convert_iter_for_each_to_for::convert_iter_for_each_to_for,
219220
convert_iter_for_each_to_for::convert_for_loop_with_for_each,
220221
convert_let_else_to_match::convert_let_else_to_match,
222+
convert_named_struct_to_tuple_struct::convert_named_struct_to_tuple_struct,
221223
convert_to_guarded_return::convert_to_guarded_return,
222224
convert_tuple_struct_to_named_struct::convert_tuple_struct_to_named_struct,
223225
convert_two_arm_bool_match_to_matches_macro::convert_two_arm_bool_match_to_matches_macro,

‎crates/ide-assists/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ fn assist_order_field_struct() {
232232
assert_eq!(assists.next().expect("expected assist").label, "Generate a getter method");
233233
assert_eq!(assists.next().expect("expected assist").label, "Generate a mut getter method");
234234
assert_eq!(assists.next().expect("expected assist").label, "Generate a setter method");
235+
assert_eq!(assists.next().expect("expected assist").label, "Convert to tuple struct");
235236
assert_eq!(assists.next().expect("expected assist").label, "Add `#[derive]`");
236237
}
237238

‎crates/ide-assists/src/tests/generated.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,47 @@ fn main() {
407407
)
408408
}
409409

410+
#[test]
411+
fn doctest_convert_named_struct_to_tuple_struct() {
412+
check_doc_test(
413+
"convert_named_struct_to_tuple_struct",
414+
r#####"
415+
struct Point$0 { x: f32, y: f32 }
416+
417+
impl Point {
418+
pub fn new(x: f32, y: f32) -> Self {
419+
Point { x, y }
420+
}
421+
422+
pub fn x(&self) -> f32 {
423+
self.x
424+
}
425+
426+
pub fn y(&self) -> f32 {
427+
self.y
428+
}
429+
}
430+
"#####,
431+
r#####"
432+
struct Point(f32, f32);
433+
434+
impl Point {
435+
pub fn new(x: f32, y: f32) -> Self {
436+
Point(x, y)
437+
}
438+
439+
pub fn x(&self) -> f32 {
440+
self.0
441+
}
442+
443+
pub fn y(&self) -> f32 {
444+
self.1
445+
}
446+
}
447+
"#####,
448+
)
449+
}
450+
410451
#[test]
411452
fn doctest_convert_to_guarded_return() {
412453
check_doc_test(

0 commit comments

Comments
 (0)
This repository has been archived.