Skip to content

Commit d95644d

Browse files
committed
Simplify empty pattern logic some more
1 parent de77f1a commit d95644d

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
@@ -1450,23 +1450,19 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14501450
is_top_level && matches!(ctors_for_ty, ConstructorSet::NoConstructors);
14511451
// Whether empty patterns can be omitted for exhaustiveness.
14521452
let can_omit_empty_arms = is_toplevel_exception || mcx.tycx.is_exhaustive_patterns_feature_on();
1453+
// Whether empty patterns are counted as useful or not.
1454+
let empty_arms_are_unreachable = place_validity.is_known_valid() && can_omit_empty_arms;
14531455

14541456
// Analyze the constructors present in this column.
14551457
let ctors = matrix.heads().map(|p| p.ctor());
14561458
let mut split_set = ctors_for_ty.split(ctors);
1457-
if !can_omit_empty_arms {
1458-
// Treat all missing constructors as nonempty.
1459-
// This clears `missing_empty`.
1460-
split_set.missing.append(&mut split_set.missing_empty);
1461-
}
14621459
let all_missing = split_set.present.is_empty();
1463-
14641460
// Build the set of constructors we will specialize with. It must cover the whole type.
14651461
// We need to iterate over a full set of constructors, so we add `Missing` to represent the
14661462
// missing ones. This is explained under "Constructor Splitting" at the top of this file.
14671463
let mut split_ctors = split_set.present;
14681464
if !(split_set.missing.is_empty()
1469-
&& (split_set.missing_empty.is_empty() || place_validity.is_known_valid()))
1465+
&& (split_set.missing_empty.is_empty() || empty_arms_are_unreachable))
14701466
{
14711467
split_ctors.push(Constructor::Missing);
14721468
}
@@ -1479,7 +1475,10 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14791475
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
14801476
// split_ctors.contains(Missing)`. The converse usually holds except when
14811477
// `!place_validity.is_known_valid()`.
1482-
let missing_ctors = split_set.missing;
1478+
let mut missing_ctors = split_set.missing;
1479+
if !can_omit_empty_arms {
1480+
missing_ctors.append(&mut split_set.missing_empty);
1481+
}
14831482

14841483
let mut ret = WitnessMatrix::empty();
14851484
for ctor in split_ctors {

0 commit comments

Comments
 (0)