Skip to content

Commit b877ef2

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

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
@@ -767,30 +767,16 @@ impl<'a, 'p, Cx: TypeCx> PlaceCtxt<'a, 'p, Cx> {
767767
pub enum ValidityConstraint {
768768
ValidOnly,
769769
MaybeInvalid,
770-
/// Option for backwards compatibility: the place is not known to be valid but we allow omitting
771-
/// `useful && !reachable` arms anyway.
772-
MaybeInvalidButAllowOmittingArms,
773770
}
774771

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

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

795781
/// If the place has validity given by `self` and we read that the value at the place has
796782
/// constructor `ctor`, this computes what we can assume about the validity of the constructor
@@ -813,7 +799,7 @@ impl fmt::Display for ValidityConstraint {
813799
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
814800
let s = match self {
815801
ValidOnly => "✓",
816-
MaybeInvalid | MaybeInvalidButAllowOmittingArms => "?",
802+
MaybeInvalid => "?",
817803
};
818804
write!(f, "{s}")
819805
}
@@ -1373,8 +1359,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13731359

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

13791363
// Analyze the constructors present in this column.
13801364
let ctors = matrix.heads().map(|p| p.ctor());
@@ -1399,12 +1383,9 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
13991383
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing".
14001384
let report_individual_missing_ctors = always_report_all || !all_missing;
14011385
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
1402-
// split_ctors.contains(Missing)`. The converse usually holds except in the
1403-
// `MaybeInvalidButAllowOmittingArms` backwards-compatibility case.
1404-
let mut missing_ctors = split_set.missing;
1405-
if !place_validity.allows_omitting_empty_arms() {
1406-
missing_ctors.extend(split_set.missing_empty);
1407-
}
1386+
// split_ctors.contains(Missing)`. The converse usually holds except when
1387+
// `!place_validity.is_known_valid()`.
1388+
let missing_ctors = split_set.missing;
14081389

14091390
let mut ret = WitnessMatrix::empty();
14101391
for ctor in split_ctors {

0 commit comments

Comments
 (0)