@@ -914,22 +914,6 @@ impl<'p, 'tcx> Usefulness<'p, 'tcx> {
914
914
}
915
915
}
916
916
917
- /// When trying several branches and each returns a `Usefulness`, we need to combine the
918
- /// results together.
919
- fn merge ( pref : ArmType , usefulnesses : impl Iterator < Item = Self > ) -> Self {
920
- let mut ret = Self :: new_not_useful ( pref) ;
921
- for u in usefulnesses {
922
- ret. extend ( u) ;
923
- if let NoWitnesses ( subpats) = & ret {
924
- if subpats. is_full ( ) {
925
- // Once we reach the full set, more unions won't change the result.
926
- return ret;
927
- }
928
- }
929
- }
930
- ret
931
- }
932
-
933
917
/// After calculating the usefulness for a branch of an or-pattern, call this to make this
934
918
/// usefulness mergeable with those from the other branches.
935
919
fn unsplit_or_pat ( self , alt_id : usize , alt_count : usize , pat : & ' p Pat < ' tcx > ) -> Self {
@@ -1168,25 +1152,26 @@ fn is_useful<'p, 'tcx>(
1168
1152
let pcx = PatCtxt { cx, ty, span : v. head ( ) . span , is_top_level, is_non_exhaustive } ;
1169
1153
1170
1154
// If the first pattern is an or-pattern, expand it.
1171
- let ret = if is_or_pat ( v. head ( ) ) {
1155
+ let mut ret = Usefulness :: new_not_useful ( witness_preference) ;
1156
+ if is_or_pat ( v. head ( ) ) {
1172
1157
debug ! ( "expanding or-pattern" ) ;
1173
1158
let v_head = v. head ( ) ;
1174
1159
let vs: Vec < _ > = v. expand_or_pat ( ) . collect ( ) ;
1175
1160
let alt_count = vs. len ( ) ;
1176
1161
// We try each or-pattern branch in turn.
1177
1162
let mut matrix = matrix. clone ( ) ;
1178
- let usefulnesses = vs. into_iter ( ) . enumerate ( ) . map ( | ( i , v ) | {
1163
+ for ( i , v ) in vs. into_iter ( ) . enumerate ( ) {
1179
1164
let usefulness =
1180
1165
is_useful ( cx, & matrix, & v, witness_preference, hir_id, is_under_guard, false ) ;
1166
+ let usefulness = usefulness. unsplit_or_pat ( i, alt_count, v_head) ;
1167
+ ret. extend ( usefulness) ;
1181
1168
// If pattern has a guard don't add it to the matrix.
1182
1169
if !is_under_guard {
1183
1170
// We push the already-seen patterns into the matrix in order to detect redundant
1184
1171
// branches like `Some(_) | Some(0)`.
1185
1172
matrix. push ( v) ;
1186
1173
}
1187
- usefulness. unsplit_or_pat ( i, alt_count, v_head)
1188
- } ) ;
1189
- Usefulness :: merge ( witness_preference, usefulnesses)
1174
+ }
1190
1175
} else {
1191
1176
let v_ctor = v. head_ctor ( cx) ;
1192
1177
if let Constructor :: IntRange ( ctor_range) = & v_ctor {
@@ -1204,7 +1189,7 @@ fn is_useful<'p, 'tcx>(
1204
1189
// For each constructor, we compute whether there's a value that starts with it that would
1205
1190
// witness the usefulness of `v`.
1206
1191
let start_matrix = & matrix;
1207
- let usefulnesses = split_ctors. into_iter ( ) . map ( |ctor| {
1192
+ for ctor in split_ctors {
1208
1193
debug ! ( "specialize({:?})" , ctor) ;
1209
1194
// We cache the result of `Fields::wildcards` because it is used a lot.
1210
1195
let ctor_wild_subpatterns = Fields :: wildcards ( pcx, & ctor) ;
@@ -1213,6 +1198,8 @@ fn is_useful<'p, 'tcx>(
1213
1198
let v = v. pop_head_constructor ( & ctor_wild_subpatterns) ;
1214
1199
let usefulness =
1215
1200
is_useful ( cx, & spec_matrix, & v, witness_preference, hir_id, is_under_guard, false ) ;
1201
+ let usefulness =
1202
+ usefulness. apply_constructor ( pcx, start_matrix, & ctor, & ctor_wild_subpatterns) ;
1216
1203
1217
1204
// When all the conditions are met we have a match with a `non_exhaustive` enum
1218
1205
// that has the potential to trigger the `non_exhaustive_omitted_patterns` lint.
@@ -1248,10 +1235,9 @@ fn is_useful<'p, 'tcx>(
1248
1235
lint_non_exhaustive_omitted_patterns ( pcx. cx , pcx. ty , pcx. span , hir_id, patterns) ;
1249
1236
}
1250
1237
1251
- usefulness. apply_constructor ( pcx, start_matrix, & ctor, & ctor_wild_subpatterns)
1252
- } ) ;
1253
- Usefulness :: merge ( witness_preference, usefulnesses)
1254
- } ;
1238
+ ret. extend ( usefulness) ;
1239
+ }
1240
+ }
1255
1241
1256
1242
debug ! ( ?ret) ;
1257
1243
ret
0 commit comments