@@ -2,7 +2,7 @@ use hir::TypeInfo;
2
2
use std:: { collections:: HashMap , iter:: successors} ;
3
3
use syntax:: {
4
4
algo:: neighbor,
5
- ast:: { self , AstNode , HasName , MatchArm , Pat } ,
5
+ ast:: { self , AstNode , HasName } ,
6
6
Direction ,
7
7
} ;
8
8
@@ -90,7 +90,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option
90
90
)
91
91
}
92
92
93
- fn contains_placeholder ( a : & MatchArm ) -> bool {
93
+ fn contains_placeholder ( a : & ast :: MatchArm ) -> bool {
94
94
matches ! ( a. pat( ) , Some ( ast:: Pat :: WildcardPat ( ..) ) )
95
95
}
96
96
@@ -101,54 +101,55 @@ fn are_same_types(
101
101
) -> bool {
102
102
let arm_types = get_arm_types ( & ctx, & arm) ;
103
103
for ( other_arm_type_name, other_arm_type) in arm_types {
104
- if let ( Some ( Some ( current_arm_type ) ) , Some ( other_arm_type) ) =
105
- ( current_arm_types . get ( & other_arm_type_name ) , other_arm_type)
106
- {
107
- if other_arm_type . original != current_arm_type . original {
108
- return false ;
104
+ match ( current_arm_types . get ( & other_arm_type_name ) , other_arm_type) {
105
+ ( Some ( Some ( current_arm_type ) ) , Some ( other_arm_type) )
106
+ if other_arm_type . original == current_arm_type . original =>
107
+ {
108
+ ( )
109
109
}
110
- } else {
111
- // No corresponding field found
112
- return false ;
110
+ _ => return false ,
113
111
}
114
112
}
115
113
116
- return true ;
114
+ true
117
115
}
118
116
119
- fn get_arm_types ( context : & AssistContext , arm : & MatchArm ) -> HashMap < String , Option < TypeInfo > > {
117
+ fn get_arm_types (
118
+ context : & AssistContext ,
119
+ arm : & ast:: MatchArm ,
120
+ ) -> HashMap < String , Option < TypeInfo > > {
120
121
let mut mapping: HashMap < String , Option < TypeInfo > > = HashMap :: new ( ) ;
121
122
122
123
fn recurse (
123
- pat : & Option < Pat > ,
124
124
map : & mut HashMap < String , Option < TypeInfo > > ,
125
125
ctx : & AssistContext ,
126
+ pat : & Option < ast:: Pat > ,
126
127
) {
127
128
if let Some ( local_pat) = pat {
128
129
match pat {
129
130
Some ( ast:: Pat :: TupleStructPat ( tuple) ) => {
130
131
for field in tuple. fields ( ) {
131
- recurse ( & Some ( field) , map , ctx ) ;
132
+ recurse ( map , ctx , & Some ( field) ) ;
132
133
}
133
134
}
134
135
Some ( ast:: Pat :: TuplePat ( tuple) ) => {
135
136
for field in tuple. fields ( ) {
136
- recurse ( & Some ( field) , map , ctx ) ;
137
+ recurse ( map , ctx , & Some ( field) ) ;
137
138
}
138
139
}
139
140
Some ( ast:: Pat :: RecordPat ( record) ) => {
140
141
if let Some ( field_list) = record. record_pat_field_list ( ) {
141
142
for field in field_list. fields ( ) {
142
- recurse ( & field. pat ( ) , map , ctx ) ;
143
+ recurse ( map , ctx , & field. pat ( ) ) ;
143
144
}
144
145
}
145
146
}
146
147
Some ( ast:: Pat :: ParenPat ( parentheses) ) => {
147
- recurse ( & parentheses. pat ( ) , map , ctx ) ;
148
+ recurse ( map , ctx , & parentheses. pat ( ) ) ;
148
149
}
149
150
Some ( ast:: Pat :: SlicePat ( slice) ) => {
150
151
for slice_pat in slice. pats ( ) {
151
- recurse ( & Some ( slice_pat) , map , ctx ) ;
152
+ recurse ( map , ctx , & Some ( slice_pat) ) ;
152
153
}
153
154
}
154
155
Some ( ast:: Pat :: IdentPat ( ident_pat) ) => {
@@ -162,8 +163,8 @@ fn get_arm_types(context: &AssistContext, arm: &MatchArm) -> HashMap<String, Opt
162
163
}
163
164
}
164
165
165
- recurse ( & arm . pat ( ) , & mut mapping, & context) ;
166
- return mapping;
166
+ recurse ( & mut mapping, & context, & arm . pat ( ) ) ;
167
+ mapping
167
168
}
168
169
169
170
#[ cfg( test) ]
@@ -327,7 +328,8 @@ fn main() {
327
328
fn merge_match_arms_different_type ( ) {
328
329
check_assist_not_applicable (
329
330
merge_match_arms,
330
- r#"//- minicore: result
331
+ r#"
332
+ //- minicore: result
331
333
fn func() {
332
334
match Result::<f64, f32>::Ok(0f64) {
333
335
Ok(x) => $0x.classify(),
@@ -342,7 +344,8 @@ fn func() {
342
344
fn merge_match_arms_different_type_multiple_fields ( ) {
343
345
check_assist_not_applicable (
344
346
merge_match_arms,
345
- r#"//- minicore: result
347
+ r#"
348
+ //- minicore: result
346
349
fn func() {
347
350
match Result::<(f64, f64), (f32, f32)>::Ok((0f64, 0f64)) {
348
351
Ok(x) => $0x.1.classify(),
@@ -357,7 +360,8 @@ fn func() {
357
360
fn merge_match_arms_same_type_multiple_fields ( ) {
358
361
check_assist (
359
362
merge_match_arms,
360
- r#"//- minicore: result
363
+ r#"
364
+ //- minicore: result
361
365
fn func() {
362
366
match Result::<(f64, f64), (f64, f64)>::Ok((0f64, 0f64)) {
363
367
Ok(x) => $0x.1.classify(),
@@ -437,7 +441,8 @@ fn func(e: MyEnum) {
437
441
fn merge_match_arms_same_type_different_number_of_fields ( ) {
438
442
check_assist_not_applicable (
439
443
merge_match_arms,
440
- r#"//- minicore: result
444
+ r#"
445
+ //- minicore: result
441
446
fn func() {
442
447
match Result::<(f64, f64, f64), (f64, f64)>::Ok((0f64, 0f64, 0f64)) {
443
448
Ok(x) => $0x.1.classify(),
0 commit comments