Fix item visibilities

This commit is contained in:
Nadrieril 2023-12-11 10:56:21 +01:00
parent de3f983bcd
commit 5d6c539c2d
3 changed files with 27 additions and 31 deletions

View File

@ -253,7 +253,7 @@ pub struct IntRange {
impl IntRange { impl IntRange {
/// Best effort; will not know that e.g. `255u8..` is a singleton. /// Best effort; will not know that e.g. `255u8..` is a singleton.
pub fn is_singleton(&self) -> bool { pub(crate) fn is_singleton(&self) -> bool {
// Since `lo` and `hi` can't be the same `Infinity` and `plus_one` never changes from finite // Since `lo` and `hi` can't be the same `Infinity` and `plus_one` never changes from finite
// to infinite, this correctly only detects ranges that contain exacly one `Finite(x)`. // to infinite, this correctly only detects ranges that contain exacly one `Finite(x)`.
self.lo.plus_one() == self.hi self.lo.plus_one() == self.hi
@ -670,11 +670,11 @@ pub enum Constructor<'tcx> {
} }
impl<'tcx> Constructor<'tcx> { impl<'tcx> Constructor<'tcx> {
pub(super) fn is_non_exhaustive(&self) -> bool { pub(crate) fn is_non_exhaustive(&self) -> bool {
matches!(self, NonExhaustive) matches!(self, NonExhaustive)
} }
pub(super) fn as_variant(&self) -> Option<VariantIdx> { pub(crate) fn as_variant(&self) -> Option<VariantIdx> {
match self { match self {
Variant(i) => Some(*i), Variant(i) => Some(*i),
_ => None, _ => None,
@ -686,7 +686,7 @@ impl<'tcx> Constructor<'tcx> {
_ => None, _ => None,
} }
} }
pub(super) fn as_int_range(&self) -> Option<&IntRange> { pub(crate) fn as_int_range(&self) -> Option<&IntRange> {
match self { match self {
IntRange(range) => Some(range), IntRange(range) => Some(range),
_ => None, _ => None,
@ -830,10 +830,10 @@ pub enum ConstructorSet {
/// of the `ConstructorSet` for the type, yet if we forgot to include them in `present` we would be /// of the `ConstructorSet` for the type, yet if we forgot to include them in `present` we would be
/// ignoring any row with `Opaque`s in the algorithm. Hence the importance of point 4. /// ignoring any row with `Opaque`s in the algorithm. Hence the importance of point 4.
#[derive(Debug)] #[derive(Debug)]
pub(super) struct SplitConstructorSet<'tcx> { pub(crate) struct SplitConstructorSet<'tcx> {
pub(super) present: SmallVec<[Constructor<'tcx>; 1]>, pub(crate) present: SmallVec<[Constructor<'tcx>; 1]>,
pub(super) missing: Vec<Constructor<'tcx>>, pub(crate) missing: Vec<Constructor<'tcx>>,
pub(super) missing_empty: Vec<Constructor<'tcx>>, pub(crate) missing_empty: Vec<Constructor<'tcx>>,
} }
impl ConstructorSet { impl ConstructorSet {
@ -842,7 +842,7 @@ impl ConstructorSet {
/// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation /// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation
/// and its invariants. /// and its invariants.
#[instrument(level = "debug", skip(self, pcx, ctors), ret)] #[instrument(level = "debug", skip(self, pcx, ctors), ret)]
pub(super) fn split<'a, 'tcx>( pub(crate) fn split<'a, 'tcx>(
&self, &self,
pcx: &PatCtxt<'_, '_, 'tcx>, pcx: &PatCtxt<'_, '_, 'tcx>,
ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone, ctors: impl Iterator<Item = &'a Constructor<'tcx>> + Clone,

View File

@ -37,11 +37,11 @@ pub struct DeconstructedPat<'p, 'tcx> {
} }
impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> { impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
pub(super) fn wildcard(ty: Ty<'tcx>, span: Span) -> Self { pub fn wildcard(ty: Ty<'tcx>, span: Span) -> Self {
Self::new(Wildcard, &[], ty, span) Self::new(Wildcard, &[], ty, span)
} }
pub(super) fn new( pub fn new(
ctor: Constructor<'tcx>, ctor: Constructor<'tcx>,
fields: &'p [DeconstructedPat<'p, 'tcx>], fields: &'p [DeconstructedPat<'p, 'tcx>],
ty: Ty<'tcx>, ty: Ty<'tcx>,
@ -50,11 +50,11 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
DeconstructedPat { ctor, fields, ty, span, useful: Cell::new(false) } DeconstructedPat { ctor, fields, ty, span, useful: Cell::new(false) }
} }
pub(super) fn is_or_pat(&self) -> bool { pub(crate) fn is_or_pat(&self) -> bool {
matches!(self.ctor, Or) matches!(self.ctor, Or)
} }
/// Expand this (possibly-nested) or-pattern into its alternatives. /// Expand this (possibly-nested) or-pattern into its alternatives.
pub(super) fn flatten_or_pat(&'p self) -> SmallVec<[&'p Self; 1]> { pub(crate) fn flatten_or_pat(&'p self) -> SmallVec<[&'p Self; 1]> {
if self.is_or_pat() { if self.is_or_pat() {
self.iter_fields().flat_map(|p| p.flatten_or_pat()).collect() self.iter_fields().flat_map(|p| p.flatten_or_pat()).collect()
} else { } else {
@ -80,7 +80,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
/// Specialize this pattern with a constructor. /// Specialize this pattern with a constructor.
/// `other_ctor` can be different from `self.ctor`, but must be covered by it. /// `other_ctor` can be different from `self.ctor`, but must be covered by it.
pub(super) fn specialize<'a>( pub(crate) fn specialize<'a>(
&'a self, &'a self,
pcx: &PatCtxt<'_, 'p, 'tcx>, pcx: &PatCtxt<'_, 'p, 'tcx>,
other_ctor: &Constructor<'tcx>, other_ctor: &Constructor<'tcx>,
@ -122,10 +122,10 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
/// We keep track for each pattern if it was ever useful during the analysis. This is used /// We keep track for each pattern if it was ever useful during the analysis. This is used
/// with `redundant_spans` to report redundant subpatterns arising from or patterns. /// with `redundant_spans` to report redundant subpatterns arising from or patterns.
pub(super) fn set_useful(&self) { pub(crate) fn set_useful(&self) {
self.useful.set(true) self.useful.set(true)
} }
pub(super) fn is_useful(&self) -> bool { pub(crate) fn is_useful(&self) -> bool {
if self.useful.get() { if self.useful.get() {
true true
} else if self.is_or_pat() && self.iter_fields().any(|f| f.is_useful()) { } else if self.is_or_pat() && self.iter_fields().any(|f| f.is_useful()) {
@ -140,7 +140,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
} }
/// Report the spans of subpatterns that were not useful, if any. /// Report the spans of subpatterns that were not useful, if any.
pub(super) fn redundant_spans(&self) -> Vec<Span> { pub(crate) fn redundant_spans(&self) -> Vec<Span> {
let mut spans = Vec::new(); let mut spans = Vec::new();
self.collect_redundant_spans(&mut spans); self.collect_redundant_spans(&mut spans);
spans spans
@ -175,17 +175,17 @@ pub struct WitnessPat<'tcx> {
} }
impl<'tcx> WitnessPat<'tcx> { impl<'tcx> WitnessPat<'tcx> {
pub(super) fn new(ctor: Constructor<'tcx>, fields: Vec<Self>, ty: Ty<'tcx>) -> Self { pub(crate) fn new(ctor: Constructor<'tcx>, fields: Vec<Self>, ty: Ty<'tcx>) -> Self {
Self { ctor, fields, ty } Self { ctor, fields, ty }
} }
pub(super) fn wildcard(ty: Ty<'tcx>) -> Self { pub(crate) fn wildcard(ty: Ty<'tcx>) -> Self {
Self::new(Wildcard, Vec::new(), ty) Self::new(Wildcard, Vec::new(), ty)
} }
/// Construct a pattern that matches everything that starts with this constructor. /// Construct a pattern that matches everything that starts with this constructor.
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern /// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
/// `Some(_)`. /// `Some(_)`.
pub(super) fn wild_from_ctor(pcx: &PatCtxt<'_, '_, 'tcx>, ctor: Constructor<'tcx>) -> Self { pub(crate) fn wild_from_ctor(pcx: &PatCtxt<'_, '_, 'tcx>, ctor: Constructor<'tcx>) -> Self {
let field_tys = let field_tys =
pcx.cx.ctor_wildcard_fields(&ctor, pcx.ty).iter().map(|deco_pat| deco_pat.ty()); pcx.cx.ctor_wildcard_fields(&ctor, pcx.ty).iter().map(|deco_pat| deco_pat.ty());
let fields = field_tys.map(|ty| Self::wildcard(ty)).collect(); let fields = field_tys.map(|ty| Self::wildcard(ty)).collect();

View File

@ -594,7 +594,7 @@ impl<'a, 'p, 'tcx> fmt::Debug for PatCtxt<'a, 'p, 'tcx> {
/// - in the matrix, track whether a given place (aka column) is known to contain a valid value or /// - in the matrix, track whether a given place (aka column) is known to contain a valid value or
/// not. /// not.
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(super) enum ValidityConstraint { enum ValidityConstraint {
ValidOnly, ValidOnly,
MaybeInvalid, MaybeInvalid,
/// Option for backwards compatibility: the place is not known to be valid but we allow omitting /// Option for backwards compatibility: the place is not known to be valid but we allow omitting
@ -603,7 +603,7 @@ pub(super) enum ValidityConstraint {
} }
impl ValidityConstraint { impl ValidityConstraint {
pub(super) fn from_bool(is_valid_only: bool) -> Self { fn from_bool(is_valid_only: bool) -> Self {
if is_valid_only { ValidOnly } else { MaybeInvalid } if is_valid_only { ValidOnly } else { MaybeInvalid }
} }
@ -615,10 +615,10 @@ impl ValidityConstraint {
} }
} }
pub(super) fn is_known_valid(self) -> bool { fn is_known_valid(self) -> bool {
matches!(self, ValidOnly) matches!(self, ValidOnly)
} }
pub(super) fn allows_omitting_empty_arms(self) -> bool { fn allows_omitting_empty_arms(self) -> bool {
matches!(self, ValidOnly | MaybeInvalidButAllowOmittingArms) matches!(self, ValidOnly | MaybeInvalidButAllowOmittingArms)
} }
@ -628,11 +628,7 @@ impl ValidityConstraint {
/// ///
/// Pending further opsem decisions, the current behavior is: validity is preserved, except /// Pending further opsem decisions, the current behavior is: validity is preserved, except
/// inside `&` and union fields where validity is reset to `MaybeInvalid`. /// inside `&` and union fields where validity is reset to `MaybeInvalid`.
pub(super) fn specialize<'tcx>( fn specialize<'tcx>(self, pcx: &PatCtxt<'_, '_, 'tcx>, ctor: &Constructor<'tcx>) -> Self {
self,
pcx: &PatCtxt<'_, '_, 'tcx>,
ctor: &Constructor<'tcx>,
) -> Self {
// We preserve validity except when we go inside a reference or a union field. // We preserve validity except when we go inside a reference or a union field.
if matches!(ctor, Constructor::Single) if matches!(ctor, Constructor::Single)
&& (matches!(pcx.ty.kind(), ty::Ref(..)) && (matches!(pcx.ty.kind(), ty::Ref(..))
@ -1023,7 +1019,7 @@ impl<'p, 'tcx> fmt::Debug for Matrix<'p, 'tcx> {
/// ///
/// See the top of the file for more detailed explanations and examples. /// See the top of the file for more detailed explanations and examples.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub(crate) struct WitnessStack<'tcx>(Vec<WitnessPat<'tcx>>); struct WitnessStack<'tcx>(Vec<WitnessPat<'tcx>>);
impl<'tcx> WitnessStack<'tcx> { impl<'tcx> WitnessStack<'tcx> {
/// Asserts that the witness contains a single pattern, and returns it. /// Asserts that the witness contains a single pattern, and returns it.
@ -1070,7 +1066,7 @@ impl<'tcx> WitnessStack<'tcx> {
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single /// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
/// column, which contains the patterns that are missing for the match to be exhaustive. /// column, which contains the patterns that are missing for the match to be exhaustive.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct WitnessMatrix<'tcx>(Vec<WitnessStack<'tcx>>); struct WitnessMatrix<'tcx>(Vec<WitnessStack<'tcx>>);
impl<'tcx> WitnessMatrix<'tcx> { impl<'tcx> WitnessMatrix<'tcx> {
/// New matrix with no witnesses. /// New matrix with no witnesses.