diff --git a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs index 994e1a01a07..cac4bec3d14 100644 --- a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs +++ b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs @@ -160,7 +160,7 @@ fn edit_struct_references( .to_string(), ); }, - _ => () + _ => return None, } } Some(()) @@ -170,7 +170,9 @@ fn edit_struct_references( edit.edit_file(file_id); for r in refs { for node in r.name.syntax().ancestors() { - edit_node(edit, node); + if edit_node(edit, node).is_some() { + break; + } } } } @@ -377,6 +379,49 @@ fn into_second(self) -> u64 { ); } + #[test] + fn convert_struct_with_wrapped_references() { + check_assist( + convert_tuple_struct_to_named_struct, + r#" +struct Inner$0(u32); +struct Outer(Inner); + +impl Outer { + fn new() -> Self { + Self(Inner(42)) + } + + fn into_inner(self) -> u32 { + (self.0).0 + } + + fn into_inner_destructed(self) -> u32 { + let Outer(Inner(x)) = self; + x + } +}"#, + r#" +struct Inner { field1: u32 } +struct Outer(Inner); + +impl Outer { + fn new() -> Self { + Self(Inner { field1: 42 }) + } + + fn into_inner(self) -> u32 { + (self.0).field1 + } + + fn into_inner_destructed(self) -> u32 { + let Outer(Inner { field1: x }) = self; + x + } +}"#, + ); + } + #[test] fn convert_struct_with_multi_file_references() { check_assist(