diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2023-12-15 16:32:44 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2023-12-15 16:58:38 +0100 |
| commit | 60ea14bfaab32d2d1d5f956acfd08d72a2a79e1c (patch) | |
| tree | d7493db58bc59ad2611acd9a5cd5988f31519dea /compiler/rustc_pattern_analysis/src | |
| parent | 1e89a38423ee1b562e3b10278d0097d88bc48f5f (diff) | |
| download | rust-60ea14bfaab32d2d1d5f956acfd08d72a2a79e1c.tar.gz rust-60ea14bfaab32d2d1d5f956acfd08d72a2a79e1c.zip | |
s/PatCtxt/PlaceCtxt/
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/constructor.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lints.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/pat.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/usefulness.rs | 36 |
5 files changed, 33 insertions, 33 deletions
diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 2093c511032..ec1ddd56b1c 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -162,7 +162,7 @@ use self::Constructor::*; use self::MaybeInfiniteInt::*; use self::SliceKind::*; -use crate::usefulness::PatCtxt; +use crate::usefulness::PlaceCtxt; use crate::MatchCx; /// Whether we have seen a constructor in the column or not. @@ -717,7 +717,7 @@ impl<Cx: MatchCx> Constructor<Cx> { /// The number of fields for this constructor. This must be kept in sync with /// `Fields::wildcards`. - pub(crate) fn arity(&self, pcx: &PatCtxt<'_, '_, Cx>) -> usize { + pub(crate) fn arity(&self, pcx: &PlaceCtxt<'_, '_, Cx>) -> usize { pcx.cx.ctor_arity(self, pcx.ty) } @@ -726,7 +726,7 @@ impl<Cx: MatchCx> Constructor<Cx> { /// this checks for inclusion. // We inline because this has a single call site in `Matrix::specialize_constructor`. #[inline] - pub(crate) fn is_covered_by<'p>(&self, pcx: &PatCtxt<'_, 'p, Cx>, other: &Self) -> bool { + pub(crate) fn is_covered_by<'p>(&self, pcx: &PlaceCtxt<'_, 'p, Cx>, other: &Self) -> bool { match (self, other) { (Wildcard, _) => pcx .cx @@ -859,7 +859,7 @@ impl<Cx: MatchCx> ConstructorSet<Cx> { #[instrument(level = "debug", skip(self, pcx, ctors), ret)] pub(crate) fn split<'a>( &self, - pcx: &PatCtxt<'_, '_, Cx>, + pcx: &PlaceCtxt<'_, '_, Cx>, ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone, ) -> SplitConstructorSet<Cx> where @@ -1008,7 +1008,7 @@ impl<Cx: MatchCx> ConstructorSet<Cx> { // In the absence of the `exhaustive_patterns` feature however, we don't count nested empty // types as empty. Only non-nested `!` or `enum Foo {}` are considered empty. if !pcx.cx.is_exhaustive_patterns_feature_on() - && !(pcx.is_top_level && matches!(self, Self::NoConstructors)) + && !(pcx.is_scrutinee && matches!(self, Self::NoConstructors)) { // Treat all missing constructors as nonempty. // This clears `missing_empty`. diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index 6c00a265b69..2d4b06669b5 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -13,7 +13,7 @@ use crate::errors::{ OverlappingRangeEndpoints, Uncovered, }; use crate::rustc::{ - Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcMatchCheckCtxt, SplitConstructorSet, + Constructor, DeconstructedPat, MatchArm, PlaceCtxt, RustcMatchCheckCtxt, SplitConstructorSet, WitnessPat, }; use crate::MatchCx; @@ -68,7 +68,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> { } /// Do constructor splitting on the constructors of the column. - fn analyze_ctors(&self, pcx: &PatCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> { + fn analyze_ctors(&self, pcx: &PlaceCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> { let column_ctors = self.patterns.iter().map(|p| p.ctor()); pcx.cx.ctors_for_ty(pcx.ty).split(pcx, column_ctors) } @@ -84,7 +84,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> { /// which may change the lengths. fn specialize( &self, - pcx: &PatCtxt<'a, 'p, 'tcx>, + pcx: &PlaceCtxt<'a, 'p, 'tcx>, ctor: &Constructor<'p, 'tcx>, ) -> Vec<PatternColumn<'a, 'p, 'tcx>> { let arity = ctor.arity(pcx); @@ -130,7 +130,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>( let Some(ty) = column.head_ty() else { return Vec::new(); }; - let pcx = &PatCtxt::new_dummy(cx, ty, wildcard_arena); + let pcx = &PlaceCtxt::new_dummy(cx, ty, wildcard_arena); let set = column.analyze_ctors(pcx); if set.present.is_empty() { @@ -232,7 +232,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>( let Some(ty) = column.head_ty() else { return; }; - let pcx = &PatCtxt::new_dummy(cx, ty, wildcard_arena); + let pcx = &PlaceCtxt::new_dummy(cx, ty, wildcard_arena); let set = column.analyze_ctors(pcx); diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs index daaf62dca3d..4ddd5eb630a 100644 --- a/compiler/rustc_pattern_analysis/src/pat.rs +++ b/compiler/rustc_pattern_analysis/src/pat.rs @@ -6,7 +6,7 @@ use std::fmt; use smallvec::{smallvec, SmallVec}; use crate::constructor::{Constructor, Slice, SliceKind}; -use crate::usefulness::PatCtxt; +use crate::usefulness::PlaceCtxt; use crate::{Captures, MatchCx}; use self::Constructor::*; @@ -77,7 +77,7 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> { /// `other_ctor` can be different from `self.ctor`, but must be covered by it. pub(crate) fn specialize<'a>( &self, - pcx: &PatCtxt<'a, 'p, Cx>, + pcx: &PlaceCtxt<'a, 'p, Cx>, other_ctor: &Constructor<Cx>, ) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]> { let wildcard_sub_tys = || { @@ -178,7 +178,7 @@ impl<Cx: MatchCx> WitnessPat<Cx> { /// 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 /// `Some(_)`. - pub(crate) fn wild_from_ctor(pcx: &PatCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self { + pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self { let field_tys = pcx.cx.ctor_sub_tys(&ctor, pcx.ty); let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect(); Self::new(ctor, fields, pcx.ty) diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index e5347ce6363..d9b8b3a39c0 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -31,8 +31,8 @@ pub type ConstructorSet<'p, 'tcx> = pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>; pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>; -pub(crate) type PatCtxt<'a, 'p, 'tcx> = - crate::usefulness::PatCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>; +pub(crate) type PlaceCtxt<'a, 'p, 'tcx> = + crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>; pub(crate) type SplitConstructorSet<'p, 'tcx> = crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>; pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>; diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index 88d28c8f483..9742507fef2 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -575,35 +575,35 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R { f() } +/// Context that provides information local to a place under investigation. #[derive(Clone)] -pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> { +pub(crate) struct PlaceCtxt<'a, 'p, Cx: MatchCx> { pub(crate) cx: &'a Cx, - /// Type of the current column under investigation. - pub(crate) ty: Cx::Ty, - /// Whether the current pattern is the whole pattern as found in a match arm, or if it's a - /// subpattern. - pub(crate) is_top_level: bool, /// An arena to store the wildcards we produce during analysis. pub(crate) wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>, + /// Type of the place under investigation. + pub(crate) ty: Cx::Ty, + /// Whether the place is the original scrutinee place, as opposed to a subplace of it. + pub(crate) is_scrutinee: bool, } -impl<'a, 'p, Cx: MatchCx> PatCtxt<'a, 'p, Cx> { - /// A `PatCtxt` when code other than `is_useful` needs one. +impl<'a, 'p, Cx: MatchCx> PlaceCtxt<'a, 'p, Cx> { + /// A `PlaceCtxt` when code other than `is_useful` needs one. #[cfg_attr(not(feature = "rustc"), allow(dead_code))] pub(crate) fn new_dummy( cx: &'a Cx, ty: Cx::Ty, wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>, ) -> Self { - PatCtxt { cx, ty, is_top_level: false, wildcard_arena } + PlaceCtxt { cx, ty, is_scrutinee: false, wildcard_arena } } } -impl<'a, 'p, Cx: MatchCx> Copy for PatCtxt<'a, 'p, Cx> {} +impl<'a, 'p, Cx: MatchCx> Copy for PlaceCtxt<'a, 'p, Cx> {} -impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatCtxt<'a, 'p, Cx> { +impl<'a, 'p, Cx: MatchCx> fmt::Debug for PlaceCtxt<'a, 'p, Cx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("PatCtxt").field("ty", &self.ty).finish() + f.debug_struct("PlaceCtxt").field("ty", &self.ty).finish() } } @@ -714,7 +714,7 @@ impl<'a, 'p, Cx: MatchCx> PatStack<'a, 'p, Cx> { /// Only call if `ctor.is_covered_by(self.head().ctor())` is true. fn pop_head_constructor( &self, - pcx: &PatCtxt<'a, 'p, Cx>, + pcx: &PlaceCtxt<'a, 'p, Cx>, ctor: &Constructor<Cx>, ) -> PatStack<'a, 'p, Cx> { // We pop the head pattern and push the new fields extracted from the arguments of @@ -785,7 +785,7 @@ impl<'a, 'p, Cx: MatchCx> MatrixRow<'a, 'p, Cx> { /// Only call if `ctor.is_covered_by(self.head().ctor())` is true. fn pop_head_constructor( &self, - pcx: &PatCtxt<'a, 'p, Cx>, + pcx: &PlaceCtxt<'a, 'p, Cx>, ctor: &Constructor<Cx>, parent_row: usize, ) -> MatrixRow<'a, 'p, Cx> { @@ -914,7 +914,7 @@ impl<'a, 'p, Cx: MatchCx> Matrix<'a, 'p, Cx> { /// This computes `specialize(ctor, self)`. See top of the file for explanations. fn specialize_constructor( &self, - pcx: &PatCtxt<'a, 'p, Cx>, + pcx: &PlaceCtxt<'a, 'p, Cx>, ctor: &Constructor<Cx>, ) -> Matrix<'a, 'p, Cx> { let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor); @@ -1064,7 +1064,7 @@ impl<Cx: MatchCx> WitnessStack<Cx> { /// pats: [(false, "foo"), _, true] /// result: [Enum::Variant { a: (false, "foo"), b: _ }, true] /// ``` - fn apply_constructor(&mut self, pcx: &PatCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) { + fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) { let len = self.0.len(); let arity = ctor.arity(pcx); let fields = self.0.drain((len - arity)..).rev().collect(); @@ -1114,7 +1114,7 @@ impl<Cx: MatchCx> WitnessMatrix<Cx> { /// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file. fn apply_constructor( &mut self, - pcx: &PatCtxt<'_, '_, Cx>, + pcx: &PlaceCtxt<'_, '_, Cx>, missing_ctors: &[Constructor<Cx>], ctor: &Constructor<Cx>, report_individual_missing_ctors: bool, @@ -1202,7 +1202,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: MatchCx>( }; debug!("ty: {ty:?}"); - let pcx = &PatCtxt { cx, ty, is_top_level, wildcard_arena }; + let pcx = &PlaceCtxt { cx, ty, is_scrutinee: is_top_level, wildcard_arena }; // Whether the place/column we are inspecting is known to contain valid data. let place_validity = matrix.place_validity[0]; |
