mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Rename Skip
to PrivateUninhabited
This commit is contained in:
parent
39441e4cdd
commit
c918893b63
@ -688,10 +688,9 @@ pub enum Constructor<Cx: TypeCx> {
|
||||
/// Fake extra constructor for constructors that are not seen in the matrix, as explained at the
|
||||
/// top of the file.
|
||||
Missing,
|
||||
/// Fake extra constructor that indicates that we should skip the column entirely. This is used
|
||||
/// when a private field is empty, so that we don't observe its emptiness. Only used for
|
||||
/// specialization.
|
||||
Skip,
|
||||
/// Fake extra constructor that indicates and empty field that is private. When we encounter one
|
||||
/// we skip the column entirely so we don't observe its emptiness. Only used for specialization.
|
||||
PrivateUninhabited,
|
||||
}
|
||||
|
||||
impl<Cx: TypeCx> Clone for Constructor<Cx> {
|
||||
@ -713,7 +712,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
|
||||
Constructor::NonExhaustive => Constructor::NonExhaustive,
|
||||
Constructor::Hidden => Constructor::Hidden,
|
||||
Constructor::Missing => Constructor::Missing,
|
||||
Constructor::Skip => Constructor::Skip,
|
||||
Constructor::PrivateUninhabited => Constructor::PrivateUninhabited,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -768,8 +767,8 @@ impl<Cx: TypeCx> Constructor<Cx> {
|
||||
}
|
||||
// Wildcards cover anything
|
||||
(_, Wildcard) => true,
|
||||
// `Skip` skips everything.
|
||||
(Skip, _) => true,
|
||||
// `PrivateUninhabited` skips everything.
|
||||
(PrivateUninhabited, _) => true,
|
||||
// Only a wildcard pattern can match these special constructors.
|
||||
(Missing { .. } | NonExhaustive | Hidden, _) => false,
|
||||
|
||||
|
@ -82,9 +82,10 @@ use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
|
||||
pub trait Captures<'a> {}
|
||||
impl<'a, T: ?Sized> Captures<'a> for T {}
|
||||
|
||||
/// `bool` newtype that indicates whether we should skip this field during analysis.
|
||||
/// `bool` newtype that indicates whether this is a privately uninhabited field that we should skip
|
||||
/// during analysis.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SkipField(pub bool);
|
||||
pub struct PrivateUninhabitedField(pub bool);
|
||||
|
||||
/// Context that provides type information about constructors.
|
||||
///
|
||||
@ -114,7 +115,7 @@ pub trait TypeCx: Sized + fmt::Debug {
|
||||
&'a self,
|
||||
ctor: &'a Constructor<Self>,
|
||||
ty: &'a Self::Ty,
|
||||
) -> impl Iterator<Item = (Self::Ty, SkipField)> + ExactSizeIterator + Captures<'a>;
|
||||
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>;
|
||||
|
||||
/// The set of all the constructors for `ty`.
|
||||
///
|
||||
|
@ -5,7 +5,7 @@ use std::fmt;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
use crate::constructor::{Constructor, Slice, SliceKind};
|
||||
use crate::{SkipField, TypeCx};
|
||||
use crate::{PrivateUninhabitedField, TypeCx};
|
||||
|
||||
use self::Constructor::*;
|
||||
|
||||
@ -80,7 +80,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
|
||||
// Return a wildcard for each field of `other_ctor`.
|
||||
(Wildcard, _) => wildcard_sub_tys(),
|
||||
// Skip this column.
|
||||
(_, Skip) => smallvec![],
|
||||
(_, PrivateUninhabited) => smallvec![],
|
||||
// The only non-trivial case: two slices of different arity. `other_slice` is
|
||||
// guaranteed to have a larger arity, so we fill the middle part with enough
|
||||
// wildcards to reach the length of the new, larger slice.
|
||||
@ -189,7 +189,9 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Wildcard | Missing | NonExhaustive | Hidden | Skip => write!(f, "_ : {:?}", pat.ty()),
|
||||
Wildcard | Missing | NonExhaustive | Hidden | PrivateUninhabited => {
|
||||
write!(f, "_ : {:?}", pat.ty())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -299,7 +301,7 @@ impl<Cx: TypeCx> WitnessPat<Cx> {
|
||||
pub(crate) fn wild_from_ctor(cx: &Cx, ctor: Constructor<Cx>, ty: Cx::Ty) -> Self {
|
||||
let fields = cx
|
||||
.ctor_sub_tys(&ctor, &ty)
|
||||
.filter(|(_, SkipField(skip))| !skip)
|
||||
.filter(|(_, PrivateUninhabitedField(skip))| !skip)
|
||||
.map(|(ty, _)| Self::wildcard(ty))
|
||||
.collect();
|
||||
Self::new(ctor, fields, ty)
|
||||
|
@ -18,7 +18,7 @@ use rustc_target::abi::{FieldIdx, Integer, VariantIdx, FIRST_VARIANT};
|
||||
use crate::constructor::{
|
||||
IntRange, MaybeInfiniteInt, OpaqueId, RangeEnd, Slice, SliceKind, VariantVisibility,
|
||||
};
|
||||
use crate::{errors, Captures, SkipField, TypeCx};
|
||||
use crate::{errors, Captures, PrivateUninhabitedField, TypeCx};
|
||||
|
||||
use crate::constructor::Constructor::*;
|
||||
|
||||
@ -195,14 +195,16 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||
&'a self,
|
||||
ctor: &'a Constructor<'p, 'tcx>,
|
||||
ty: RevealedTy<'tcx>,
|
||||
) -> impl Iterator<Item = (RevealedTy<'tcx>, SkipField)> + ExactSizeIterator + Captures<'a>
|
||||
{
|
||||
) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)>
|
||||
+ ExactSizeIterator
|
||||
+ Captures<'a> {
|
||||
fn reveal_and_alloc<'a, 'tcx>(
|
||||
cx: &'a RustcMatchCheckCtxt<'_, 'tcx>,
|
||||
iter: impl Iterator<Item = Ty<'tcx>>,
|
||||
) -> &'a [(RevealedTy<'tcx>, SkipField)] {
|
||||
) -> &'a [(RevealedTy<'tcx>, PrivateUninhabitedField)] {
|
||||
cx.dropless_arena.alloc_from_iter(
|
||||
iter.map(|ty| cx.reveal_opaque_ty(ty)).map(|ty| (ty, SkipField(false))),
|
||||
iter.map(|ty| cx.reveal_opaque_ty(ty))
|
||||
.map(|ty| (ty, PrivateUninhabitedField(false))),
|
||||
)
|
||||
}
|
||||
let cx = self;
|
||||
@ -230,7 +232,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||
|| cx.tcx.features().min_exhaustive_patterns)
|
||||
&& cx.is_uninhabited(*ty);
|
||||
let skip = is_uninhabited && (!is_visible || is_non_exhaustive);
|
||||
(ty, SkipField(skip))
|
||||
(ty, PrivateUninhabitedField(skip))
|
||||
});
|
||||
cx.dropless_arena.alloc_from_iter(tys)
|
||||
}
|
||||
@ -249,7 +251,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty),
|
||||
},
|
||||
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||
| NonExhaustive | Hidden | Missing | Skip | Wildcard => &[],
|
||||
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => &[],
|
||||
Or => {
|
||||
bug!("called `Fields::wildcards` on an `Or` ctor")
|
||||
}
|
||||
@ -277,7 +279,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||
Ref => 1,
|
||||
Slice(slice) => slice.arity(),
|
||||
Bool(..) | IntRange(..) | F32Range(..) | F64Range(..) | Str(..) | Opaque(..)
|
||||
| NonExhaustive | Hidden | Missing | Skip | Wildcard => 0,
|
||||
| NonExhaustive | Hidden | Missing | PrivateUninhabited | Wildcard => 0,
|
||||
Or => bug!("The `Or` constructor doesn't have a fixed arity"),
|
||||
}
|
||||
}
|
||||
@ -805,7 +807,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
|
||||
}
|
||||
}
|
||||
&Str(value) => PatKind::Constant { value },
|
||||
Wildcard | NonExhaustive | Hidden | Skip => PatKind::Wild,
|
||||
Wildcard | NonExhaustive | Hidden | PrivateUninhabited => PatKind::Wild,
|
||||
Missing { .. } => bug!(
|
||||
"trying to convert a `Missing` constructor into a `Pat`; this is probably a bug,
|
||||
`Missing` should have been processed in `apply_constructors`"
|
||||
@ -841,7 +843,8 @@ impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
|
||||
&'a self,
|
||||
ctor: &'a crate::constructor::Constructor<Self>,
|
||||
ty: &'a Self::Ty,
|
||||
) -> impl Iterator<Item = (Self::Ty, SkipField)> + ExactSizeIterator + Captures<'a> {
|
||||
) -> impl Iterator<Item = (Self::Ty, PrivateUninhabitedField)> + ExactSizeIterator + Captures<'a>
|
||||
{
|
||||
self.ctor_sub_tys(ctor, *ty)
|
||||
}
|
||||
fn ctors_for_ty(
|
||||
|
@ -716,7 +716,7 @@ use std::fmt;
|
||||
|
||||
use crate::constructor::{Constructor, ConstructorSet, IntRange};
|
||||
use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat};
|
||||
use crate::{Captures, MatchArm, SkipField, TypeCx};
|
||||
use crate::{Captures, MatchArm, PrivateUninhabitedField, TypeCx};
|
||||
|
||||
use self::ValidityConstraint::*;
|
||||
|
||||
@ -817,9 +817,9 @@ impl fmt::Display for ValidityConstraint {
|
||||
struct PlaceInfo<Cx: TypeCx> {
|
||||
/// The type of the place.
|
||||
ty: Cx::Ty,
|
||||
/// Whether we must skip this field during analysis. This is used when a private field is empty,
|
||||
/// Whether the place is a private uninhabited field. If so we skip this field during analysis
|
||||
/// so that we don't observe its emptiness.
|
||||
skip: SkipField,
|
||||
private_uninhabited: bool,
|
||||
/// Whether the place is known to contain valid data.
|
||||
validity: ValidityConstraint,
|
||||
/// Whether the place is the scrutinee itself or a subplace of it.
|
||||
@ -836,9 +836,9 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
|
||||
) -> impl Iterator<Item = Self> + ExactSizeIterator + Captures<'a> {
|
||||
let ctor_sub_tys = cx.ctor_sub_tys(ctor, &self.ty);
|
||||
let ctor_sub_validity = self.validity.specialize(ctor);
|
||||
ctor_sub_tys.map(move |(ty, skip)| PlaceInfo {
|
||||
ctor_sub_tys.map(move |(ty, PrivateUninhabitedField(private_uninhabited))| PlaceInfo {
|
||||
ty,
|
||||
skip,
|
||||
private_uninhabited,
|
||||
validity: ctor_sub_validity,
|
||||
is_scrutinee: false,
|
||||
})
|
||||
@ -860,9 +860,9 @@ impl<Cx: TypeCx> PlaceInfo<Cx> {
|
||||
where
|
||||
Cx: 'a,
|
||||
{
|
||||
if matches!(self.skip, SkipField(true)) {
|
||||
if self.private_uninhabited {
|
||||
// Skip the whole column
|
||||
return Ok((smallvec![Constructor::Skip], vec![]));
|
||||
return Ok((smallvec![Constructor::PrivateUninhabited], vec![]));
|
||||
}
|
||||
|
||||
let ctors_for_ty = cx.ctors_for_ty(&self.ty)?;
|
||||
@ -925,7 +925,7 @@ impl<Cx: TypeCx> Clone for PlaceInfo<Cx> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
ty: self.ty.clone(),
|
||||
skip: self.skip,
|
||||
private_uninhabited: self.private_uninhabited,
|
||||
validity: self.validity,
|
||||
is_scrutinee: self.is_scrutinee,
|
||||
}
|
||||
@ -1137,7 +1137,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
|
||||
) -> Self {
|
||||
let place_info = PlaceInfo {
|
||||
ty: scrut_ty,
|
||||
skip: SkipField(false),
|
||||
private_uninhabited: false,
|
||||
validity: scrut_validity,
|
||||
is_scrutinee: true,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user