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

Commit cb15bf6

Browse files
committed
Rename ValidityConstraint -> PlaceValidity
The old name came from a time where I wanted to reuse it for differentiating wildcards from bindings. I don't plan to do this anymore.
1 parent 9ce37dc commit cb15bf6

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

compiler/rustc_pattern_analysis/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ pub fn analyze_match<'p, 'tcx>(
179179
pattern_complexity_limit: Option<usize>,
180180
) -> Result<rustc::UsefulnessReport<'p, 'tcx>, ErrorGuaranteed> {
181181
use lints::lint_nonexhaustive_missing_variants;
182-
use usefulness::{compute_match_usefulness, ValidityConstraint};
182+
use usefulness::{compute_match_usefulness, PlaceValidity};
183183

184184
let scrut_ty = tycx.reveal_opaque_ty(scrut_ty);
185-
let scrut_validity = ValidityConstraint::from_bool(tycx.known_valid_scrutinee);
185+
let scrut_validity = PlaceValidity::from_bool(tycx.known_valid_scrutinee);
186186
let report =
187187
compute_match_usefulness(tycx, arms, scrut_ty, scrut_validity, pattern_complexity_limit)?;
188188

compiler/rustc_pattern_analysis/src/usefulness.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@
540540
//! We track in the algorithm whether a given place is known to contain valid data. This is done
541541
//! first by inspecting the scrutinee syntactically (which gives us `cx.known_valid_scrutinee`), and
542542
//! then by tracking validity of each column of the matrix (which correspond to places) as we
543-
//! recurse into subpatterns. That second part is done through [`ValidityConstraint`], most notably
544-
//! [`ValidityConstraint::specialize`].
543+
//! recurse into subpatterns. That second part is done through [`PlaceValidity`], most notably
544+
//! [`PlaceValidity::specialize`].
545545
//!
546546
//! Having said all that, in practice we don't fully follow what's been presented in this section.
547547
//! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or
@@ -718,7 +718,7 @@ use crate::constructor::{Constructor, ConstructorSet, IntRange};
718718
use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat};
719719
use crate::{Captures, MatchArm, PrivateUninhabitedField, TypeCx};
720720

721-
use self::ValidityConstraint::*;
721+
use self::PlaceValidity::*;
722722

723723
#[cfg(feature = "rustc")]
724724
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -780,18 +780,14 @@ impl<'a, Cx: TypeCx> PlaceCtxt<'a, Cx> {
780780
}
781781
}
782782

783-
/// Serves two purposes:
784-
/// - in a wildcard, tracks whether the wildcard matches only valid values (i.e. is a binding `_a`)
785-
/// or also invalid values (i.e. is a true `_` pattern).
786-
/// - in the matrix, track whether a given place (aka column) is known to contain a valid value or
787-
/// not.
783+
/// Track whether a given place (aka column) is known to contain a valid value or not.
788784
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
789-
pub enum ValidityConstraint {
785+
pub enum PlaceValidity {
790786
ValidOnly,
791787
MaybeInvalid,
792788
}
793789

794-
impl ValidityConstraint {
790+
impl PlaceValidity {
795791
pub fn from_bool(is_valid_only: bool) -> Self {
796792
if is_valid_only { ValidOnly } else { MaybeInvalid }
797793
}
@@ -817,7 +813,7 @@ impl ValidityConstraint {
817813
}
818814
}
819815

820-
impl fmt::Display for ValidityConstraint {
816+
impl fmt::Display for PlaceValidity {
821817
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
822818
let s = match self {
823819
ValidOnly => "✓",
@@ -836,7 +832,7 @@ struct PlaceInfo<Cx: TypeCx> {
836832
/// so that we don't observe its emptiness.
837833
private_uninhabited: bool,
838834
/// Whether the place is known to contain valid data.
839-
validity: ValidityConstraint,
835+
validity: PlaceValidity,
840836
/// Whether the place is the scrutinee itself or a subplace of it.
841837
is_scrutinee: bool,
842838
}
@@ -1155,11 +1151,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
11551151
}
11561152

11571153
/// Build a new matrix from an iterator of `MatchArm`s.
1158-
fn new(
1159-
arms: &[MatchArm<'p, Cx>],
1160-
scrut_ty: Cx::Ty,
1161-
scrut_validity: ValidityConstraint,
1162-
) -> Self {
1154+
fn new(arms: &[MatchArm<'p, Cx>], scrut_ty: Cx::Ty, scrut_validity: PlaceValidity) -> Self {
11631155
let place_info = PlaceInfo {
11641156
ty: scrut_ty,
11651157
private_uninhabited: false,
@@ -1754,7 +1746,7 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
17541746
tycx: &Cx,
17551747
arms: &[MatchArm<'p, Cx>],
17561748
scrut_ty: Cx::Ty,
1757-
scrut_validity: ValidityConstraint,
1749+
scrut_validity: PlaceValidity,
17581750
complexity_limit: Option<usize>,
17591751
) -> Result<UsefulnessReport<'p, Cx>, Cx::Error> {
17601752
let mut cx = UsefulnessCtxt {

0 commit comments

Comments
 (0)