Skip to content

Commit da765a8

Browse files
committed
Simplify use of ValidityConstraint
We had reached a point where the shenanigans about omitting empty arms are unnecessary.
1 parent 1411efc commit da765a8

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

compiler/rustc_pattern_analysis/src/usefulness.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -768,30 +768,16 @@ impl<'a, Cx: TypeCx> PlaceCtxt<'a, Cx> {
768768
pub enum ValidityConstraint {
769769
ValidOnly,
770770
MaybeInvalid,
771-
/// Option for backwards compatibility: the place is not known to be valid but we allow omitting
772-
/// `useful && !reachable` arms anyway.
773-
MaybeInvalidButAllowOmittingArms,
774771
}
775772

776773
impl ValidityConstraint {
777774
pub fn from_bool(is_valid_only: bool) -> Self {
778775
if is_valid_only { ValidOnly } else { MaybeInvalid }
779776
}
780777

781-
fn allow_omitting_side_effecting_arms(self) -> Self {
782-
match self {
783-
MaybeInvalid | MaybeInvalidButAllowOmittingArms => MaybeInvalidButAllowOmittingArms,
784-
// There are no side-effecting empty arms here, nothing to do.
785-
ValidOnly => ValidOnly,
786-
}
787-
}
788-
789778
fn is_known_valid(self) -> bool {
790779
matches!(self, ValidOnly)
791780
}
792-
fn allows_omitting_empty_arms(self) -> bool {
793-
matches!(self, ValidOnly | MaybeInvalidButAllowOmittingArms)
794-
}
795781

796782
/// If the place has validity given by `self` and we read that the value at the place has
797783
/// constructor `ctor`, this computes what we can assume about the validity of the constructor
@@ -814,7 +800,7 @@ impl fmt::Display for ValidityConstraint {
814800
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
815801
let s = match self {
816802
ValidOnly => "✓",
817-
MaybeInvalid | MaybeInvalidButAllowOmittingArms => "?",
803+
MaybeInvalid => "?",
818804
};
819805
write!(f, "{s}")
820806
}
@@ -1451,8 +1437,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14511437

14521438
// Whether the place/column we are inspecting is known to contain valid data.
14531439
let place_validity = matrix.place_validity[0];
1454-
// For backwards compability we allow omitting some empty arms that we ideally shouldn't.
1455-
let place_validity = place_validity.allow_omitting_side_effecting_arms();
14561440

14571441
// Analyze the constructors present in this column.
14581442
let ctors = matrix.heads().map(|p| p.ctor());
@@ -1477,12 +1461,9 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14771461
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing".
14781462
let report_individual_missing_ctors = always_report_all || !all_missing;
14791463
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
1480-
// split_ctors.contains(Missing)`. The converse usually holds except in the
1481-
// `MaybeInvalidButAllowOmittingArms` backwards-compatibility case.
1482-
let mut missing_ctors = split_set.missing;
1483-
if !place_validity.allows_omitting_empty_arms() {
1484-
missing_ctors.extend(split_set.missing_empty);
1485-
}
1464+
// split_ctors.contains(Missing)`. The converse usually holds except when
1465+
// `!place_validity.is_known_valid()`.
1466+
let missing_ctors = split_set.missing;
14861467

14871468
let mut ret = WitnessMatrix::empty();
14881469
for ctor in split_ctors {

0 commit comments

Comments
 (0)