diff options
| author | bors <bors@rust-lang.org> | 2022-11-25 09:41:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-11-25 09:41:21 +0000 |
| commit | e668eca632e57eb67f15c267019bcb8581518daa (patch) | |
| tree | 20badd56b67d6e1146ea27805f73830452beadaf | |
| parent | 99daf23e11df1b1f9354be789eb7456cebf0c549 (diff) | |
| parent | 23cfe0702de3a7144be6842bf54d94091b0cde6d (diff) | |
| download | rust-e668eca632e57eb67f15c267019bcb8581518daa.tar.gz rust-e668eca632e57eb67f15c267019bcb8581518daa.zip | |
Auto merge of #13647 - nyz93:fix/tuple-to-named-struct, r=Veykril
fix: tuple to named struct inside macros seems to fix #13634
| -rw-r--r-- | crates/ide-assists/src/handlers/convert_tuple_struct_to_named_struct.rs | 43 |
1 files changed, 42 insertions, 1 deletions
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 92e091fca12..b0383291e73 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 @@ -168,7 +168,7 @@ fn edit_struct_references( let arg_list = call_expr.syntax().descendants().find_map(ast::ArgList::cast)?; edit.replace( - call_expr.syntax().text_range(), + ctx.sema.original_range(&node).range, ast::make::record_expr( path, ast::make::record_expr_field_list(arg_list.args().zip(names).map( @@ -249,6 +249,24 @@ mod tests { ); check_assist_not_applicable(convert_tuple_struct_to_named_struct, r#"struct Foo$0;"#); } + #[test] + fn convert_in_macro_args() { + check_assist( + convert_tuple_struct_to_named_struct, + r#" +macro_rules! foo {($i:expr) => {$i} } +struct T$0(u8); +fn test() { + foo!(T(1)); +}"#, + r#" +macro_rules! foo {($i:expr) => {$i} } +struct T { field1: u8 } +fn test() { + foo!(T { field1: 1 }); +}"#, + ); + } #[test] fn convert_simple_struct() { @@ -555,6 +573,29 @@ where } #[test] + fn convert_variant_in_macro_args() { + check_assist( + convert_tuple_struct_to_named_struct, + r#" +macro_rules! foo {($i:expr) => {$i} } +enum T { + V$0(u8) +} +fn test() { + foo!(T::V(1)); +}"#, + r#" +macro_rules! foo {($i:expr) => {$i} } +enum T { + V { field1: u8 } +} +fn test() { + foo!(T::V { field1: 1 }); +}"#, + ); + } + + #[test] fn convert_simple_variant() { check_assist( convert_tuple_struct_to_named_struct, |
