Skip to content

Commit 4fc35c4

Browse files
committed
Rename TypeCx -> PatCx
1 parent cb15bf6 commit 4fc35c4

File tree

6 files changed

+68
-68
lines changed

6 files changed

+68
-68
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
//! - That have no non-trivial intersection with any of the constructors in the column (i.e. they're
4141
//! each either disjoint with or covered by any given column constructor).
4242
//!
43-
//! We compute this in two steps: first [`TypeCx::ctors_for_ty`] determines the
43+
//! We compute this in two steps: first [`PatCx::ctors_for_ty`] determines the
4444
//! set of all possible constructors for the type. Then [`ConstructorSet::split`] looks at the
4545
//! column of constructors and splits the set into groups accordingly. The precise invariants of
4646
//! [`ConstructorSet::split`] is described in [`SplitConstructorSet`].
@@ -136,7 +136,7 @@
136136
//! the algorithm can't distinguish them from a nonempty constructor. The only known case where this
137137
//! could happen is the `[..]` pattern on `[!; N]` with `N > 0` so we must take care to not emit it.
138138
//!
139-
//! This is all handled by [`TypeCx::ctors_for_ty`] and
139+
//! This is all handled by [`PatCx::ctors_for_ty`] and
140140
//! [`ConstructorSet::split`]. The invariants of [`SplitConstructorSet`] are also of interest.
141141
//!
142142
//!
@@ -162,7 +162,7 @@ use self::MaybeInfiniteInt::*;
162162
use self::SliceKind::*;
163163

164164
use crate::index;
165-
use crate::TypeCx;
165+
use crate::PatCx;
166166

167167
/// Whether we have seen a constructor in the column or not.
168168
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
@@ -651,7 +651,7 @@ impl OpaqueId {
651651
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
652652
/// `Fields`.
653653
#[derive(Debug)]
654-
pub enum Constructor<Cx: TypeCx> {
654+
pub enum Constructor<Cx: PatCx> {
655655
/// Tuples and structs.
656656
Struct,
657657
/// Enum variants.
@@ -696,7 +696,7 @@ pub enum Constructor<Cx: TypeCx> {
696696
PrivateUninhabited,
697697
}
698698

699-
impl<Cx: TypeCx> Clone for Constructor<Cx> {
699+
impl<Cx: PatCx> Clone for Constructor<Cx> {
700700
fn clone(&self) -> Self {
701701
match self {
702702
Constructor::Struct => Constructor::Struct,
@@ -720,7 +720,7 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
720720
}
721721
}
722722

723-
impl<Cx: TypeCx> Constructor<Cx> {
723+
impl<Cx: PatCx> Constructor<Cx> {
724724
pub(crate) fn is_non_exhaustive(&self) -> bool {
725725
matches!(self, NonExhaustive)
726726
}
@@ -838,7 +838,7 @@ pub enum VariantVisibility {
838838
/// In terms of division of responsibility, [`ConstructorSet::split`] handles all of the
839839
/// `exhaustive_patterns` feature.
840840
#[derive(Debug)]
841-
pub enum ConstructorSet<Cx: TypeCx> {
841+
pub enum ConstructorSet<Cx: PatCx> {
842842
/// The type is a tuple or struct. `empty` tracks whether the type is empty.
843843
Struct { empty: bool },
844844
/// This type has the following list of constructors. If `variants` is empty and
@@ -889,13 +889,13 @@ pub enum ConstructorSet<Cx: TypeCx> {
889889
/// of the `ConstructorSet` for the type, yet if we forgot to include them in `present` we would be
890890
/// ignoring any row with `Opaque`s in the algorithm. Hence the importance of point 4.
891891
#[derive(Debug)]
892-
pub struct SplitConstructorSet<Cx: TypeCx> {
892+
pub struct SplitConstructorSet<Cx: PatCx> {
893893
pub present: SmallVec<[Constructor<Cx>; 1]>,
894894
pub missing: Vec<Constructor<Cx>>,
895895
pub missing_empty: Vec<Constructor<Cx>>,
896896
}
897897

898-
impl<Cx: TypeCx> ConstructorSet<Cx> {
898+
impl<Cx: PatCx> ConstructorSet<Cx> {
899899
/// This analyzes a column of constructors to 1/ determine which constructors of the type (if
900900
/// any) are missing; 2/ split constructors to handle non-trivial intersections e.g. on ranges
901901
/// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation

compiler/rustc_pattern_analysis/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct PrivateUninhabitedField(pub bool);
8484
/// Context that provides type information about constructors.
8585
///
8686
/// Most of the crate is parameterized on a type that implements this trait.
87-
pub trait TypeCx: Sized + fmt::Debug {
87+
pub trait PatCx: Sized + fmt::Debug {
8888
/// The type of a pattern.
8989
type Ty: Clone + fmt::Debug;
9090
/// Errors that can abort analysis.
@@ -155,19 +155,19 @@ pub trait TypeCx: Sized + fmt::Debug {
155155

156156
/// The arm of a match expression.
157157
#[derive(Debug)]
158-
pub struct MatchArm<'p, Cx: TypeCx> {
158+
pub struct MatchArm<'p, Cx: PatCx> {
159159
pub pat: &'p DeconstructedPat<Cx>,
160160
pub has_guard: bool,
161161
pub arm_data: Cx::ArmData,
162162
}
163163

164-
impl<'p, Cx: TypeCx> Clone for MatchArm<'p, Cx> {
164+
impl<'p, Cx: PatCx> Clone for MatchArm<'p, Cx> {
165165
fn clone(&self) -> Self {
166166
Self { pat: self.pat, has_guard: self.has_guard, arm_data: self.arm_data }
167167
}
168168
}
169169

170-
impl<'p, Cx: TypeCx> Copy for MatchArm<'p, Cx> {}
170+
impl<'p, Cx: PatCx> Copy for MatchArm<'p, Cx> {}
171171

172172
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
173173
/// useful, and runs some lints.

compiler/rustc_pattern_analysis/src/pat.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt;
55
use smallvec::{smallvec, SmallVec};
66

77
use crate::constructor::{Constructor, Slice, SliceKind};
8-
use crate::{PrivateUninhabitedField, TypeCx};
8+
use crate::{PatCx, PrivateUninhabitedField};
99

1010
use self::Constructor::*;
1111

@@ -21,15 +21,15 @@ impl PatId {
2121
}
2222

2323
/// A pattern with an index denoting which field it corresponds to.
24-
pub struct IndexedPat<Cx: TypeCx> {
24+
pub struct IndexedPat<Cx: PatCx> {
2525
pub idx: usize,
2626
pub pat: DeconstructedPat<Cx>,
2727
}
2828

2929
/// Values and patterns can be represented as a constructor applied to some fields. This represents
3030
/// a pattern in this form. A `DeconstructedPat` will almost always come from user input; the only
3131
/// exception are some `Wildcard`s introduced during pattern lowering.
32-
pub struct DeconstructedPat<Cx: TypeCx> {
32+
pub struct DeconstructedPat<Cx: PatCx> {
3333
ctor: Constructor<Cx>,
3434
fields: Vec<IndexedPat<Cx>>,
3535
/// The number of fields in this pattern. E.g. if the pattern is `SomeStruct { field12: true, ..
@@ -43,7 +43,7 @@ pub struct DeconstructedPat<Cx: TypeCx> {
4343
pub(crate) uid: PatId,
4444
}
4545

46-
impl<Cx: TypeCx> DeconstructedPat<Cx> {
46+
impl<Cx: PatCx> DeconstructedPat<Cx> {
4747
pub fn new(
4848
ctor: Constructor<Cx>,
4949
fields: Vec<IndexedPat<Cx>>,
@@ -136,7 +136,7 @@ impl<Cx: TypeCx> DeconstructedPat<Cx> {
136136
}
137137

138138
/// This is best effort and not good enough for a `Display` impl.
139-
impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
139+
impl<Cx: PatCx> fmt::Debug for DeconstructedPat<Cx> {
140140
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
141141
let pat = self;
142142
let mut first = true;
@@ -219,14 +219,14 @@ impl<Cx: TypeCx> fmt::Debug for DeconstructedPat<Cx> {
219219
/// algorithm. Do not use `Wild` to represent a wildcard pattern comping from user input.
220220
///
221221
/// This is morally `Option<&'p DeconstructedPat>` where `None` is interpreted as a wildcard.
222-
pub(crate) enum PatOrWild<'p, Cx: TypeCx> {
222+
pub(crate) enum PatOrWild<'p, Cx: PatCx> {
223223
/// A non-user-provided wildcard, created during specialization.
224224
Wild,
225225
/// A user-provided pattern.
226226
Pat(&'p DeconstructedPat<Cx>),
227227
}
228228

229-
impl<'p, Cx: TypeCx> Clone for PatOrWild<'p, Cx> {
229+
impl<'p, Cx: PatCx> Clone for PatOrWild<'p, Cx> {
230230
fn clone(&self) -> Self {
231231
match self {
232232
PatOrWild::Wild => PatOrWild::Wild,
@@ -235,9 +235,9 @@ impl<'p, Cx: TypeCx> Clone for PatOrWild<'p, Cx> {
235235
}
236236
}
237237

238-
impl<'p, Cx: TypeCx> Copy for PatOrWild<'p, Cx> {}
238+
impl<'p, Cx: PatCx> Copy for PatOrWild<'p, Cx> {}
239239

240-
impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
240+
impl<'p, Cx: PatCx> PatOrWild<'p, Cx> {
241241
pub(crate) fn as_pat(&self) -> Option<&'p DeconstructedPat<Cx>> {
242242
match self {
243243
PatOrWild::Wild => None,
@@ -283,7 +283,7 @@ impl<'p, Cx: TypeCx> PatOrWild<'p, Cx> {
283283
}
284284
}
285285

286-
impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {
286+
impl<'p, Cx: PatCx> fmt::Debug for PatOrWild<'p, Cx> {
287287
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
288288
match self {
289289
PatOrWild::Wild => write!(f, "_"),
@@ -295,19 +295,19 @@ impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {
295295
/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
296296
/// purposes. As such they don't use interning and can be cloned.
297297
#[derive(Debug)]
298-
pub struct WitnessPat<Cx: TypeCx> {
298+
pub struct WitnessPat<Cx: PatCx> {
299299
ctor: Constructor<Cx>,
300300
pub(crate) fields: Vec<WitnessPat<Cx>>,
301301
ty: Cx::Ty,
302302
}
303303

304-
impl<Cx: TypeCx> Clone for WitnessPat<Cx> {
304+
impl<Cx: PatCx> Clone for WitnessPat<Cx> {
305305
fn clone(&self) -> Self {
306306
Self { ctor: self.ctor.clone(), fields: self.fields.clone(), ty: self.ty.clone() }
307307
}
308308
}
309309

310-
impl<Cx: TypeCx> WitnessPat<Cx> {
310+
impl<Cx: PatCx> WitnessPat<Cx> {
311311
pub(crate) fn new(ctor: Constructor<Cx>, fields: Vec<Self>, ty: Cx::Ty) -> Self {
312312
Self { ctor, fields, ty }
313313
}

compiler/rustc_pattern_analysis/src/pat_column.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::constructor::{Constructor, SplitConstructorSet};
22
use crate::pat::{DeconstructedPat, PatOrWild};
3-
use crate::{Captures, MatchArm, TypeCx};
3+
use crate::{Captures, MatchArm, PatCx};
44

55
/// A column of patterns in a match, where a column is the intuitive notion of "subpatterns that
66
/// inspect the same subvalue/place".
@@ -11,12 +11,12 @@ use crate::{Captures, MatchArm, TypeCx};
1111
///
1212
/// This is not used in the usefulness algorithm; only in lints.
1313
#[derive(Debug)]
14-
pub struct PatternColumn<'p, Cx: TypeCx> {
14+
pub struct PatternColumn<'p, Cx: PatCx> {
1515
/// This must not contain an or-pattern. `expand_and_push` takes care to expand them.
1616
patterns: Vec<&'p DeconstructedPat<Cx>>,
1717
}
1818

19-
impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
19+
impl<'p, Cx: PatCx> PatternColumn<'p, Cx> {
2020
pub fn new(arms: &[MatchArm<'p, Cx>]) -> Self {
2121
let patterns = Vec::with_capacity(arms.len());
2222
let mut column = PatternColumn { patterns };

compiler/rustc_pattern_analysis/src/rustc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_target::abi::{FieldIdx, Integer, VariantIdx, FIRST_VARIANT};
1818
use crate::constructor::{
1919
IntRange, MaybeInfiniteInt, OpaqueId, RangeEnd, Slice, SliceKind, VariantVisibility,
2020
};
21-
use crate::{errors, Captures, PrivateUninhabitedField, TypeCx};
21+
use crate::{errors, Captures, PatCx, PrivateUninhabitedField};
2222

2323
use crate::constructor::Constructor::*;
2424

@@ -843,7 +843,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
843843
}
844844
}
845845

846-
impl<'p, 'tcx: 'p> TypeCx for RustcMatchCheckCtxt<'p, 'tcx> {
846+
impl<'p, 'tcx: 'p> PatCx for RustcMatchCheckCtxt<'p, 'tcx> {
847847
type Ty = RevealedTy<'tcx>;
848848
type Error = ErrorGuaranteed;
849849
type VariantIdx = VariantIdx;

0 commit comments

Comments
 (0)