Skip to content

Commit 60ea14b

Browse files
committed
s/PatCtxt/PlaceCtxt/
1 parent 1e89a38 commit 60ea14b

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ use self::Constructor::*;
162162
use self::MaybeInfiniteInt::*;
163163
use self::SliceKind::*;
164164

165-
use crate::usefulness::PatCtxt;
165+
use crate::usefulness::PlaceCtxt;
166166
use crate::MatchCx;
167167

168168
/// Whether we have seen a constructor in the column or not.
@@ -717,7 +717,7 @@ impl<Cx: MatchCx> Constructor<Cx> {
717717

718718
/// The number of fields for this constructor. This must be kept in sync with
719719
/// `Fields::wildcards`.
720-
pub(crate) fn arity(&self, pcx: &PatCtxt<'_, '_, Cx>) -> usize {
720+
pub(crate) fn arity(&self, pcx: &PlaceCtxt<'_, '_, Cx>) -> usize {
721721
pcx.cx.ctor_arity(self, pcx.ty)
722722
}
723723

@@ -726,7 +726,7 @@ impl<Cx: MatchCx> Constructor<Cx> {
726726
/// this checks for inclusion.
727727
// We inline because this has a single call site in `Matrix::specialize_constructor`.
728728
#[inline]
729-
pub(crate) fn is_covered_by<'p>(&self, pcx: &PatCtxt<'_, 'p, Cx>, other: &Self) -> bool {
729+
pub(crate) fn is_covered_by<'p>(&self, pcx: &PlaceCtxt<'_, 'p, Cx>, other: &Self) -> bool {
730730
match (self, other) {
731731
(Wildcard, _) => pcx
732732
.cx
@@ -859,7 +859,7 @@ impl<Cx: MatchCx> ConstructorSet<Cx> {
859859
#[instrument(level = "debug", skip(self, pcx, ctors), ret)]
860860
pub(crate) fn split<'a>(
861861
&self,
862-
pcx: &PatCtxt<'_, '_, Cx>,
862+
pcx: &PlaceCtxt<'_, '_, Cx>,
863863
ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone,
864864
) -> SplitConstructorSet<Cx>
865865
where
@@ -1008,7 +1008,7 @@ impl<Cx: MatchCx> ConstructorSet<Cx> {
10081008
// In the absence of the `exhaustive_patterns` feature however, we don't count nested empty
10091009
// types as empty. Only non-nested `!` or `enum Foo {}` are considered empty.
10101010
if !pcx.cx.is_exhaustive_patterns_feature_on()
1011-
&& !(pcx.is_top_level && matches!(self, Self::NoConstructors))
1011+
&& !(pcx.is_scrutinee && matches!(self, Self::NoConstructors))
10121012
{
10131013
// Treat all missing constructors as nonempty.
10141014
// This clears `missing_empty`.

compiler/rustc_pattern_analysis/src/lints.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::errors::{
1313
OverlappingRangeEndpoints, Uncovered,
1414
};
1515
use crate::rustc::{
16-
Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcMatchCheckCtxt, SplitConstructorSet,
16+
Constructor, DeconstructedPat, MatchArm, PlaceCtxt, RustcMatchCheckCtxt, SplitConstructorSet,
1717
WitnessPat,
1818
};
1919
use crate::MatchCx;
@@ -68,7 +68,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
6868
}
6969

7070
/// Do constructor splitting on the constructors of the column.
71-
fn analyze_ctors(&self, pcx: &PatCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> {
71+
fn analyze_ctors(&self, pcx: &PlaceCtxt<'_, 'p, 'tcx>) -> SplitConstructorSet<'p, 'tcx> {
7272
let column_ctors = self.patterns.iter().map(|p| p.ctor());
7373
pcx.cx.ctors_for_ty(pcx.ty).split(pcx, column_ctors)
7474
}
@@ -84,7 +84,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
8484
/// which may change the lengths.
8585
fn specialize(
8686
&self,
87-
pcx: &PatCtxt<'a, 'p, 'tcx>,
87+
pcx: &PlaceCtxt<'a, 'p, 'tcx>,
8888
ctor: &Constructor<'p, 'tcx>,
8989
) -> Vec<PatternColumn<'a, 'p, 'tcx>> {
9090
let arity = ctor.arity(pcx);
@@ -130,7 +130,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
130130
let Some(ty) = column.head_ty() else {
131131
return Vec::new();
132132
};
133-
let pcx = &PatCtxt::new_dummy(cx, ty, wildcard_arena);
133+
let pcx = &PlaceCtxt::new_dummy(cx, ty, wildcard_arena);
134134

135135
let set = column.analyze_ctors(pcx);
136136
if set.present.is_empty() {
@@ -232,7 +232,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
232232
let Some(ty) = column.head_ty() else {
233233
return;
234234
};
235-
let pcx = &PatCtxt::new_dummy(cx, ty, wildcard_arena);
235+
let pcx = &PlaceCtxt::new_dummy(cx, ty, wildcard_arena);
236236

237237
let set = column.analyze_ctors(pcx);
238238

compiler/rustc_pattern_analysis/src/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt;
66
use smallvec::{smallvec, SmallVec};
77

88
use crate::constructor::{Constructor, Slice, SliceKind};
9-
use crate::usefulness::PatCtxt;
9+
use crate::usefulness::PlaceCtxt;
1010
use crate::{Captures, MatchCx};
1111

1212
use self::Constructor::*;
@@ -77,7 +77,7 @@ impl<'p, Cx: MatchCx> DeconstructedPat<'p, Cx> {
7777
/// `other_ctor` can be different from `self.ctor`, but must be covered by it.
7878
pub(crate) fn specialize<'a>(
7979
&self,
80-
pcx: &PatCtxt<'a, 'p, Cx>,
80+
pcx: &PlaceCtxt<'a, 'p, Cx>,
8181
other_ctor: &Constructor<Cx>,
8282
) -> SmallVec<[&'a DeconstructedPat<'p, Cx>; 2]> {
8383
let wildcard_sub_tys = || {
@@ -178,7 +178,7 @@ impl<Cx: MatchCx> WitnessPat<Cx> {
178178
/// Construct a pattern that matches everything that starts with this constructor.
179179
/// For example, if `ctor` is a `Constructor::Variant` for `Option::Some`, we get the pattern
180180
/// `Some(_)`.
181-
pub(crate) fn wild_from_ctor(pcx: &PatCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self {
181+
pub(crate) fn wild_from_ctor(pcx: &PlaceCtxt<'_, '_, Cx>, ctor: Constructor<Cx>) -> Self {
182182
let field_tys = pcx.cx.ctor_sub_tys(&ctor, pcx.ty);
183183
let fields = field_tys.iter().map(|ty| Self::wildcard(*ty)).collect();
184184
Self::new(ctor, fields, pcx.ty)

compiler/rustc_pattern_analysis/src/rustc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub type ConstructorSet<'p, 'tcx> =
3131
pub type DeconstructedPat<'p, 'tcx> =
3232
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3333
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
34-
pub(crate) type PatCtxt<'a, 'p, 'tcx> =
35-
crate::usefulness::PatCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
34+
pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
35+
crate::usefulness::PlaceCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3636
pub(crate) type SplitConstructorSet<'p, 'tcx> =
3737
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
3838
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;

compiler/rustc_pattern_analysis/src/usefulness.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -575,35 +575,35 @@ pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
575575
f()
576576
}
577577

578+
/// Context that provides information local to a place under investigation.
578579
#[derive(Clone)]
579-
pub(crate) struct PatCtxt<'a, 'p, Cx: MatchCx> {
580+
pub(crate) struct PlaceCtxt<'a, 'p, Cx: MatchCx> {
580581
pub(crate) cx: &'a Cx,
581-
/// Type of the current column under investigation.
582-
pub(crate) ty: Cx::Ty,
583-
/// Whether the current pattern is the whole pattern as found in a match arm, or if it's a
584-
/// subpattern.
585-
pub(crate) is_top_level: bool,
586582
/// An arena to store the wildcards we produce during analysis.
587583
pub(crate) wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
584+
/// Type of the place under investigation.
585+
pub(crate) ty: Cx::Ty,
586+
/// Whether the place is the original scrutinee place, as opposed to a subplace of it.
587+
pub(crate) is_scrutinee: bool,
588588
}
589589

590-
impl<'a, 'p, Cx: MatchCx> PatCtxt<'a, 'p, Cx> {
591-
/// A `PatCtxt` when code other than `is_useful` needs one.
590+
impl<'a, 'p, Cx: MatchCx> PlaceCtxt<'a, 'p, Cx> {
591+
/// A `PlaceCtxt` when code other than `is_useful` needs one.
592592
#[cfg_attr(not(feature = "rustc"), allow(dead_code))]
593593
pub(crate) fn new_dummy(
594594
cx: &'a Cx,
595595
ty: Cx::Ty,
596596
wildcard_arena: &'a TypedArena<DeconstructedPat<'p, Cx>>,
597597
) -> Self {
598-
PatCtxt { cx, ty, is_top_level: false, wildcard_arena }
598+
PlaceCtxt { cx, ty, is_scrutinee: false, wildcard_arena }
599599
}
600600
}
601601

602-
impl<'a, 'p, Cx: MatchCx> Copy for PatCtxt<'a, 'p, Cx> {}
602+
impl<'a, 'p, Cx: MatchCx> Copy for PlaceCtxt<'a, 'p, Cx> {}
603603

604-
impl<'a, 'p, Cx: MatchCx> fmt::Debug for PatCtxt<'a, 'p, Cx> {
604+
impl<'a, 'p, Cx: MatchCx> fmt::Debug for PlaceCtxt<'a, 'p, Cx> {
605605
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
606-
f.debug_struct("PatCtxt").field("ty", &self.ty).finish()
606+
f.debug_struct("PlaceCtxt").field("ty", &self.ty).finish()
607607
}
608608
}
609609

@@ -714,7 +714,7 @@ impl<'a, 'p, Cx: MatchCx> PatStack<'a, 'p, Cx> {
714714
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
715715
fn pop_head_constructor(
716716
&self,
717-
pcx: &PatCtxt<'a, 'p, Cx>,
717+
pcx: &PlaceCtxt<'a, 'p, Cx>,
718718
ctor: &Constructor<Cx>,
719719
) -> PatStack<'a, 'p, Cx> {
720720
// 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> {
785785
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
786786
fn pop_head_constructor(
787787
&self,
788-
pcx: &PatCtxt<'a, 'p, Cx>,
788+
pcx: &PlaceCtxt<'a, 'p, Cx>,
789789
ctor: &Constructor<Cx>,
790790
parent_row: usize,
791791
) -> MatrixRow<'a, 'p, Cx> {
@@ -914,7 +914,7 @@ impl<'a, 'p, Cx: MatchCx> Matrix<'a, 'p, Cx> {
914914
/// This computes `specialize(ctor, self)`. See top of the file for explanations.
915915
fn specialize_constructor(
916916
&self,
917-
pcx: &PatCtxt<'a, 'p, Cx>,
917+
pcx: &PlaceCtxt<'a, 'p, Cx>,
918918
ctor: &Constructor<Cx>,
919919
) -> Matrix<'a, 'p, Cx> {
920920
let wildcard_row = self.wildcard_row.pop_head_constructor(pcx, ctor);
@@ -1064,7 +1064,7 @@ impl<Cx: MatchCx> WitnessStack<Cx> {
10641064
/// pats: [(false, "foo"), _, true]
10651065
/// result: [Enum::Variant { a: (false, "foo"), b: _ }, true]
10661066
/// ```
1067-
fn apply_constructor(&mut self, pcx: &PatCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) {
1067+
fn apply_constructor(&mut self, pcx: &PlaceCtxt<'_, '_, Cx>, ctor: &Constructor<Cx>) {
10681068
let len = self.0.len();
10691069
let arity = ctor.arity(pcx);
10701070
let fields = self.0.drain((len - arity)..).rev().collect();
@@ -1114,7 +1114,7 @@ impl<Cx: MatchCx> WitnessMatrix<Cx> {
11141114
/// Reverses specialization by `ctor`. See the section on `unspecialize` at the top of the file.
11151115
fn apply_constructor(
11161116
&mut self,
1117-
pcx: &PatCtxt<'_, '_, Cx>,
1117+
pcx: &PlaceCtxt<'_, '_, Cx>,
11181118
missing_ctors: &[Constructor<Cx>],
11191119
ctor: &Constructor<Cx>,
11201120
report_individual_missing_ctors: bool,
@@ -1202,7 +1202,7 @@ fn compute_exhaustiveness_and_usefulness<'a, 'p, Cx: MatchCx>(
12021202
};
12031203

12041204
debug!("ty: {ty:?}");
1205-
let pcx = &PatCtxt { cx, ty, is_top_level, wildcard_arena };
1205+
let pcx = &PlaceCtxt { cx, ty, is_scrutinee: is_top_level, wildcard_arena };
12061206

12071207
// Whether the place/column we are inspecting is known to contain valid data.
12081208
let place_validity = matrix.place_validity[0];

0 commit comments

Comments
 (0)