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.
This commit is contained in:
Nadrieril 2024-03-13 13:53:18 +01:00
parent 9ce37dc729
commit cb15bf6256
2 changed files with 12 additions and 20 deletions

View File

@ -179,10 +179,10 @@ pub fn analyze_match<'p, 'tcx>(
pattern_complexity_limit: Option<usize>, pattern_complexity_limit: Option<usize>,
) -> Result<rustc::UsefulnessReport<'p, 'tcx>, ErrorGuaranteed> { ) -> Result<rustc::UsefulnessReport<'p, 'tcx>, ErrorGuaranteed> {
use lints::lint_nonexhaustive_missing_variants; use lints::lint_nonexhaustive_missing_variants;
use usefulness::{compute_match_usefulness, ValidityConstraint}; use usefulness::{compute_match_usefulness, PlaceValidity};
let scrut_ty = tycx.reveal_opaque_ty(scrut_ty); let scrut_ty = tycx.reveal_opaque_ty(scrut_ty);
let scrut_validity = ValidityConstraint::from_bool(tycx.known_valid_scrutinee); let scrut_validity = PlaceValidity::from_bool(tycx.known_valid_scrutinee);
let report = let report =
compute_match_usefulness(tycx, arms, scrut_ty, scrut_validity, pattern_complexity_limit)?; compute_match_usefulness(tycx, arms, scrut_ty, scrut_validity, pattern_complexity_limit)?;

View File

@ -540,8 +540,8 @@
//! We track in the algorithm whether a given place is known to contain valid data. This is done //! We track in the algorithm whether a given place is known to contain valid data. This is done
//! first by inspecting the scrutinee syntactically (which gives us `cx.known_valid_scrutinee`), and //! first by inspecting the scrutinee syntactically (which gives us `cx.known_valid_scrutinee`), and
//! then by tracking validity of each column of the matrix (which correspond to places) as we //! then by tracking validity of each column of the matrix (which correspond to places) as we
//! recurse into subpatterns. That second part is done through [`ValidityConstraint`], most notably //! recurse into subpatterns. That second part is done through [`PlaceValidity`], most notably
//! [`ValidityConstraint::specialize`]. //! [`PlaceValidity::specialize`].
//! //!
//! Having said all that, in practice we don't fully follow what's been presented in this section. //! Having said all that, in practice we don't fully follow what's been presented in this section.
//! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or //! Let's call "toplevel exception" the case where the match scrutinee itself has type `!` or
@ -718,7 +718,7 @@
use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat}; use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat};
use crate::{Captures, MatchArm, PrivateUninhabitedField, TypeCx}; use crate::{Captures, MatchArm, PrivateUninhabitedField, TypeCx};
use self::ValidityConstraint::*; use self::PlaceValidity::*;
#[cfg(feature = "rustc")] #[cfg(feature = "rustc")]
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
@ -780,18 +780,14 @@ fn wild_from_ctor(&self, ctor: Constructor<Cx>) -> WitnessPat<Cx> {
} }
} }
/// Serves two purposes: /// Track whether a given place (aka column) is known to contain a valid value or not.
/// - in a wildcard, tracks whether the wildcard matches only valid values (i.e. is a binding `_a`)
/// or also invalid values (i.e. is a true `_` pattern).
/// - in the matrix, track whether a given place (aka column) is known to contain a valid value or
/// not.
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ValidityConstraint { pub enum PlaceValidity {
ValidOnly, ValidOnly,
MaybeInvalid, MaybeInvalid,
} }
impl ValidityConstraint { impl PlaceValidity {
pub fn from_bool(is_valid_only: bool) -> Self { pub fn from_bool(is_valid_only: bool) -> Self {
if is_valid_only { ValidOnly } else { MaybeInvalid } if is_valid_only { ValidOnly } else { MaybeInvalid }
} }
@ -817,7 +813,7 @@ fn specialize<Cx: TypeCx>(self, ctor: &Constructor<Cx>) -> Self {
} }
} }
impl fmt::Display for ValidityConstraint { impl fmt::Display for PlaceValidity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self { let s = match self {
ValidOnly => "", ValidOnly => "",
@ -836,7 +832,7 @@ struct PlaceInfo<Cx: TypeCx> {
/// so that we don't observe its emptiness. /// so that we don't observe its emptiness.
private_uninhabited: bool, private_uninhabited: bool,
/// Whether the place is known to contain valid data. /// Whether the place is known to contain valid data.
validity: ValidityConstraint, validity: PlaceValidity,
/// Whether the place is the scrutinee itself or a subplace of it. /// Whether the place is the scrutinee itself or a subplace of it.
is_scrutinee: bool, is_scrutinee: bool,
} }
@ -1155,11 +1151,7 @@ fn expand_and_push(&mut self, mut row: MatrixRow<'p, Cx>) {
} }
/// Build a new matrix from an iterator of `MatchArm`s. /// Build a new matrix from an iterator of `MatchArm`s.
fn new( fn new(arms: &[MatchArm<'p, Cx>], scrut_ty: Cx::Ty, scrut_validity: PlaceValidity) -> Self {
arms: &[MatchArm<'p, Cx>],
scrut_ty: Cx::Ty,
scrut_validity: ValidityConstraint,
) -> Self {
let place_info = PlaceInfo { let place_info = PlaceInfo {
ty: scrut_ty, ty: scrut_ty,
private_uninhabited: false, private_uninhabited: false,
@ -1754,7 +1746,7 @@ pub fn compute_match_usefulness<'p, Cx: TypeCx>(
tycx: &Cx, tycx: &Cx,
arms: &[MatchArm<'p, Cx>], arms: &[MatchArm<'p, Cx>],
scrut_ty: Cx::Ty, scrut_ty: Cx::Ty,
scrut_validity: ValidityConstraint, scrut_validity: PlaceValidity,
complexity_limit: Option<usize>, complexity_limit: Option<usize>,
) -> Result<UsefulnessReport<'p, Cx>, Cx::Error> { ) -> Result<UsefulnessReport<'p, Cx>, Cx::Error> {
let mut cx = UsefulnessCtxt { let mut cx = UsefulnessCtxt {