Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bf913ad

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

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

compiler/rustc_pattern_analysis/src/usefulness.rs

Lines changed: 4 additions & 23 deletions
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
}
@@ -1460,8 +1446,6 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14601446

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

14661450
// Analyze the constructors present in this column.
14671451
let ctors = matrix.heads().map(|p| p.ctor());
@@ -1486,12 +1470,9 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: TypeCx>(
14861470
// Whether we should report "Enum::A and Enum::C are missing" or "_ is missing".
14871471
let report_individual_missing_ctors = always_report_all || !all_missing;
14881472
// Which constructors are considered missing. We ensure that `!missing_ctors.is_empty() =>
1489-
// split_ctors.contains(Missing)`. The converse usually holds except in the
1490-
// `MaybeInvalidButAllowOmittingArms` backwards-compatibility case.
1491-
let mut missing_ctors = split_set.missing;
1492-
if !place_validity.allows_omitting_empty_arms() {
1493-
missing_ctors.extend(split_set.missing_empty);
1494-
}
1473+
// split_ctors.contains(Missing)`. The converse usually holds except when
1474+
// `!place_validity.is_known_valid()`.
1475+
let missing_ctors = split_set.missing;
14951476

14961477
let mut ret = WitnessMatrix::empty();
14971478
for ctor in split_ctors {

0 commit comments

Comments
 (0)