@@ -151,26 +151,17 @@ fn check_opt_like<'a>(
151
151
return ;
152
152
}
153
153
154
- if paths_and_types. iter ( ) . all ( |info | in_candidate_enum ( cx, info ) ) {
154
+ if paths_and_types. iter ( ) . all ( |ty | in_candidate_enum ( cx, * ty ) ) {
155
155
report_single_pattern ( cx, ex, arms, expr, els) ;
156
156
}
157
157
}
158
158
159
- fn in_candidate_enum < ' a > ( cx : & LateContext < ' a > , path_info : & ( String , Ty < ' _ > ) ) -> bool {
159
+ fn in_candidate_enum < ' a > ( cx : & LateContext < ' a > , ty : Ty < ' _ > ) -> bool {
160
160
// list of candidate `Enum`s we know will never get any more members
161
- let candidates = & [
162
- ( & paths:: COW , "Borrowed" ) ,
163
- ( & paths:: COW , "Cow::Borrowed" ) ,
164
- ( & paths:: COW , "Cow::Owned" ) ,
165
- ( & paths:: COW , "Owned" ) ,
166
- ( & paths:: OPTION , "None" ) ,
167
- ( & paths:: RESULT , "Err" ) ,
168
- ( & paths:: RESULT , "Ok" ) ,
169
- ] ;
161
+ let candidates = [ & paths:: COW , & paths:: OPTION , & paths:: RESULT ] ;
170
162
171
- let ( path, ty) = path_info;
172
- for & ( ty_path, pat_path) in candidates {
173
- if path == pat_path && match_type ( cx, * ty, ty_path) {
163
+ for candidate_ty in candidates {
164
+ if match_type ( cx, ty, candidate_ty) {
174
165
return true ;
175
166
}
176
167
}
@@ -179,29 +170,15 @@ fn in_candidate_enum<'a>(cx: &LateContext<'a>, path_info: &(String, Ty<'_>)) ->
179
170
180
171
/// Collects paths and their types from the given patterns. Returns true if the given pattern could
181
172
/// be simplified, false otherwise.
182
- fn collect_pat_paths < ' a > ( acc : & mut Vec < ( String , Ty < ' a > ) > , cx : & LateContext < ' a > , pat : & Pat < ' _ > , ty : Ty < ' a > ) -> bool {
173
+ fn collect_pat_paths < ' a > ( acc : & mut Vec < Ty < ' a > > , cx : & LateContext < ' a > , pat : & Pat < ' _ > , ty : Ty < ' a > ) -> bool {
183
174
match pat. kind {
184
175
PatKind :: Wild => true ,
185
176
PatKind :: Tuple ( inner, _) => inner. iter ( ) . all ( |p| {
186
177
let p_ty = cx. typeck_results ( ) . pat_ty ( p) ;
187
178
collect_pat_paths ( acc, cx, p, p_ty)
188
179
} ) ,
189
- PatKind :: TupleStruct ( ref path, ..) => {
190
- let path = rustc_hir_pretty:: to_string ( rustc_hir_pretty:: NO_ANN , |s| {
191
- s. print_qpath ( path, false ) ;
192
- } ) ;
193
- acc. push ( ( path, ty) ) ;
194
- true
195
- } ,
196
- PatKind :: Binding ( BindingAnnotation :: Unannotated , .., ident, None ) => {
197
- acc. push ( ( ident. to_string ( ) , ty) ) ;
198
- true
199
- } ,
200
- PatKind :: Path ( ref path) => {
201
- let path = rustc_hir_pretty:: to_string ( rustc_hir_pretty:: NO_ANN , |s| {
202
- s. print_qpath ( path, false ) ;
203
- } ) ;
204
- acc. push ( ( path, ty) ) ;
180
+ PatKind :: TupleStruct ( ..) | PatKind :: Binding ( BindingAnnotation :: Unannotated , .., None ) | PatKind :: Path ( _) => {
181
+ acc. push ( ty) ;
205
182
true
206
183
} ,
207
184
_ => false ,
@@ -265,14 +242,7 @@ fn form_exhaustive_matches<'a>(cx: &LateContext<'a>, ty: Ty<'a>, left: &Pat<'_>,
265
242
}
266
243
true
267
244
} ,
268
- ( PatKind :: TupleStruct ( ..) , PatKind :: Path ( _) | PatKind :: TupleStruct ( ..) ) => {
269
- let mut paths_and_types = Vec :: new ( ) ;
270
- if !collect_pat_paths ( & mut paths_and_types, cx, right, ty) {
271
- return false ;
272
- }
273
-
274
- paths_and_types. iter ( ) . all ( |info| in_candidate_enum ( cx, info) )
275
- } ,
245
+ ( PatKind :: TupleStruct ( ..) , PatKind :: Path ( _) | PatKind :: TupleStruct ( ..) ) => in_candidate_enum ( cx, ty) ,
276
246
_ => false ,
277
247
}
278
248
}
0 commit comments