@@ -140,8 +140,10 @@ fn edit_struct_references(
140
140
match_ast ! {
141
141
match node {
142
142
ast:: TupleStructPat ( tuple_struct_pat) => {
143
+ let file_range = ctx. sema. original_range_opt( & node) ?;
144
+ edit. edit_file( file_range. file_id) ;
143
145
edit. replace(
144
- tuple_struct_pat . syntax ( ) . text_range ( ) ,
146
+ file_range . range ,
145
147
ast:: make:: record_pat_with_fields(
146
148
tuple_struct_pat. path( ) ?,
147
149
ast:: make:: record_pat_field_list( tuple_struct_pat. fields( ) . zip( names) . map(
@@ -921,6 +923,104 @@ pub struct $0Foo(#[my_custom_attr] u32);
921
923
"# ,
922
924
r#"
923
925
pub struct Foo { #[my_custom_attr] field1: u32 }
926
+ "# ,
927
+ ) ;
928
+ }
929
+
930
+ #[ test]
931
+ fn convert_in_macro_pattern_args ( ) {
932
+ check_assist (
933
+ convert_tuple_struct_to_named_struct,
934
+ r#"
935
+ macro_rules! foo {
936
+ ($expression:expr, $pattern:pat) => {
937
+ match $expression {
938
+ $pattern => true,
939
+ _ => false
940
+ }
941
+ };
942
+ }
943
+ enum Expr {
944
+ A$0(usize),
945
+ }
946
+ fn main() {
947
+ let e = Expr::A(0);
948
+ foo!(e, Expr::A(0));
949
+ }
950
+ "# ,
951
+ r#"
952
+ macro_rules! foo {
953
+ ($expression:expr, $pattern:pat) => {
954
+ match $expression {
955
+ $pattern => true,
956
+ _ => false
957
+ }
958
+ };
959
+ }
960
+ enum Expr {
961
+ A { field1: usize },
962
+ }
963
+ fn main() {
964
+ let e = Expr::A { field1: 0 };
965
+ foo!(e, Expr::A { field1: 0 });
966
+ }
967
+ "# ,
968
+ ) ;
969
+ }
970
+
971
+ #[ test]
972
+ fn convert_in_multi_file_macro_pattern_args ( ) {
973
+ check_assist (
974
+ convert_tuple_struct_to_named_struct,
975
+ r#"
976
+ //- /main.rs
977
+ mod foo;
978
+
979
+ enum Test {
980
+ A$0(i32)
981
+ }
982
+
983
+ //- /foo.rs
984
+ use crate::Test;
985
+
986
+ macro_rules! foo {
987
+ ($expression:expr, $pattern:pat) => {
988
+ match $expression {
989
+ $pattern => true,
990
+ _ => false
991
+ }
992
+ };
993
+ }
994
+
995
+ fn foo() {
996
+ let a = Test::A(0);
997
+ foo!(a, Test::A(0));
998
+ }
999
+ "# ,
1000
+ r#"
1001
+ //- /main.rs
1002
+ mod foo;
1003
+
1004
+ enum Test {
1005
+ A { field1: i32 }
1006
+ }
1007
+
1008
+ //- /foo.rs
1009
+ use crate::Test;
1010
+
1011
+ macro_rules! foo {
1012
+ ($expression:expr, $pattern:pat) => {
1013
+ match $expression {
1014
+ $pattern => true,
1015
+ _ => false
1016
+ }
1017
+ };
1018
+ }
1019
+
1020
+ fn foo() {
1021
+ let a = Test::A { field1: 0 };
1022
+ foo!(a, Test::A { field1: 0 });
1023
+ }
924
1024
"# ,
925
1025
) ;
926
1026
}
0 commit comments