Skip to content

Commit 7c28f22

Browse files
committed
Simplify empty pattern logic some more
1 parent 5399c83 commit 7c28f22

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

compiler/rustc_pattern_analysis/src/usefulness.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1368,23 +1368,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13681368
is_top_level && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
13691369
// Whether empty patterns can be omitted for exhaustiveness.
13701370
let can_omit_empty_arms = is_toplevel_exception || mcx.tycx.is_exhaustive_patterns_feature_on();
1371+
// Whether empty patterns are counted as useful or not.
1372+
let empty_arms_are_unreachable = place_validity.is_known_valid() && can_omit_empty_arms;
13711373

13721374
// Analyze the constructors present in this column.
13731375
let ctors = matrix.heads().map(|p| p.ctor());
13741376
let mut split_set = ctors_for_ty.split(ctors);
1375-
if !can_omit_empty_arms {
1376-
// Treat all missing constructors as nonempty.
1377-
// This clears `missing_empty`.
1378-
split_set.missing.append(&mut split_set.missing_empty);
1379-
}
13801377
let all_missing = split_set.present.is_empty();
1381-
13821378
// Build the set of constructors we will specialize with. It must cover the whole type.
13831379
// We need to iterate over a full set of constructors, so we add `Missing` to represent the
13841380
// missing ones. This is explained under "Constructor Splitting" at the top of this file.
13851381
let mut split_ctors = split_set.present;
13861382
if !(split_set.missing.is_empty()
1387-
&& (split_set.missing_empty.is_empty() || place_validity.is_known_valid()))
1383+
&& (split_set.missing_empty.is_empty() || empty_arms_are_unreachable))
13881384
{
13891385
split_ctors.push(Constructor::Missing);
13901386
}
@@ -1397,7 +1393,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13971393
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
13981394
// split_ctors.contains(Missing)`. The converse usually holds except when
13991395
// `!place_validity.is_known_valid()`.
1400-
let missing_ctors = split_set.missing;
1396+
let mut missing_ctors = split_set.missing;
1397+
if !can_omit_empty_arms {
1398+
missing_ctors.append(&mut split_set.missing_empty);
1399+
}
14011400

14021401
let mut ret = WitnessMatrix::empty();
14031402
for ctor in split_ctors {

0 commit comments

Comments
 (0)