Skip to content

Commit f275406

Browse files
committed
Rename RustcMatchCheckCtxt -> RustcPatCtxt
1 parent 4fc35c4 commit f275406

File tree

6 files changed

+42
-50
lines changed

6 files changed

+42
-50
lines changed

compiler/rustc_mir_build/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{
66
};
77
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
88
use rustc_middle::ty::{self, Ty};
9-
use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcMatchCheckCtxt};
9+
use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcPatCtxt};
1010
use rustc_span::symbol::Symbol;
1111
use rustc_span::Span;
1212

@@ -455,7 +455,7 @@ pub enum UnusedUnsafeEnclosing {
455455
}
456456

457457
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
458-
pub cx: &'m RustcMatchCheckCtxt<'p, 'tcx>,
458+
pub cx: &'m RustcPatCtxt<'p, 'tcx>,
459459
pub expr_span: Span,
460460
pub span: Span,
461461
pub ty: Ty<'tcx>,

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_pattern_analysis::errors::Uncovered;
22
use rustc_pattern_analysis::rustc::{
3-
Constructor, DeconstructedPat, MatchArm, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness,
4-
UsefulnessReport, WitnessPat,
3+
Constructor, DeconstructedPat, MatchArm, RustcPatCtxt as PatCtxt, Usefulness, UsefulnessReport,
4+
WitnessPat,
55
};
66

77
use crate::errors::*;
@@ -276,7 +276,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
276276

277277
fn lower_pattern(
278278
&mut self,
279-
cx: &MatchCheckCtxt<'p, 'tcx>,
279+
cx: &PatCtxt<'p, 'tcx>,
280280
pat: &'p Pat<'tcx>,
281281
) -> Result<&'p DeconstructedPat<'p, 'tcx>, ErrorGuaranteed> {
282282
if let Err(err) = pat.pat_error_reported() {
@@ -375,7 +375,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
375375
whole_match_span: Option<Span>,
376376
scrutinee: Option<&Expr<'tcx>>,
377377
scrut_span: Span,
378-
) -> MatchCheckCtxt<'p, 'tcx> {
378+
) -> PatCtxt<'p, 'tcx> {
379379
let refutable = match refutability {
380380
Irrefutable => false,
381381
Refutable => true,
@@ -384,7 +384,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
384384
// require validity.
385385
let known_valid_scrutinee =
386386
scrutinee.map(|scrut| self.is_known_valid_scrutinee(scrut)).unwrap_or(true);
387-
MatchCheckCtxt {
387+
PatCtxt {
388388
tcx: self.tcx,
389389
typeck_results: self.typeck_results,
390390
param_env: self.param_env,
@@ -400,7 +400,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
400400

401401
fn analyze_patterns(
402402
&mut self,
403-
cx: &MatchCheckCtxt<'p, 'tcx>,
403+
cx: &PatCtxt<'p, 'tcx>,
404404
arms: &[MatchArm<'p, 'tcx>],
405405
scrut_ty: Ty<'tcx>,
406406
) -> Result<UsefulnessReport<'p, 'tcx>, ErrorGuaranteed> {
@@ -584,7 +584,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
584584
pat: &'p Pat<'tcx>,
585585
refutability: RefutableFlag,
586586
scrut: Option<&Expr<'tcx>>,
587-
) -> Result<(MatchCheckCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
587+
) -> Result<(PatCtxt<'p, 'tcx>, UsefulnessReport<'p, 'tcx>), ErrorGuaranteed> {
588588
let cx = self.new_cx(refutability, None, scrut, pat.span);
589589
let pat = self.lower_pattern(&cx, pat)?;
590590
let arms = [MatchArm { pat, arm_data: self.lint_level, has_guard: false }];
@@ -849,7 +849,7 @@ fn check_for_bindings_named_same_as_variants(
849849

850850
/// Check that never patterns are only used on inhabited types.
851851
fn check_never_pattern<'tcx>(
852-
cx: &MatchCheckCtxt<'_, 'tcx>,
852+
cx: &PatCtxt<'_, 'tcx>,
853853
pat: &Pat<'tcx>,
854854
) -> Result<(), ErrorGuaranteed> {
855855
if let PatKind::Never = pat.kind {
@@ -884,7 +884,7 @@ fn report_irrefutable_let_patterns(
884884

885885
/// Report unreachable arms, if any.
886886
fn report_unreachable_pattern<'p, 'tcx>(
887-
cx: &MatchCheckCtxt<'p, 'tcx>,
887+
cx: &PatCtxt<'p, 'tcx>,
888888
hir_id: HirId,
889889
span: Span,
890890
catchall: Option<Span>,
@@ -898,10 +898,7 @@ fn report_unreachable_pattern<'p, 'tcx>(
898898
}
899899

900900
/// Report unreachable arms, if any.
901-
fn report_arm_reachability<'p, 'tcx>(
902-
cx: &MatchCheckCtxt<'p, 'tcx>,
903-
report: &UsefulnessReport<'p, 'tcx>,
904-
) {
901+
fn report_arm_reachability<'p, 'tcx>(cx: &PatCtxt<'p, 'tcx>, report: &UsefulnessReport<'p, 'tcx>) {
905902
let mut catchall = None;
906903
for (arm, is_useful) in report.arm_usefulness.iter() {
907904
if matches!(is_useful, Usefulness::Redundant) {
@@ -926,7 +923,7 @@ fn pat_is_catchall(pat: &DeconstructedPat<'_, '_>) -> bool {
926923

927924
/// Report that a match is not exhaustive.
928925
fn report_non_exhaustive_match<'p, 'tcx>(
929-
cx: &MatchCheckCtxt<'p, 'tcx>,
926+
cx: &PatCtxt<'p, 'tcx>,
930927
thir: &Thir<'tcx>,
931928
scrut_ty: Ty<'tcx>,
932929
sp: Span,
@@ -1126,7 +1123,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
11261123
}
11271124

11281125
fn joined_uncovered_patterns<'p, 'tcx>(
1129-
cx: &MatchCheckCtxt<'p, 'tcx>,
1126+
cx: &PatCtxt<'p, 'tcx>,
11301127
witnesses: &[WitnessPat<'p, 'tcx>],
11311128
) -> String {
11321129
const LIMIT: usize = 3;
@@ -1147,7 +1144,7 @@ fn joined_uncovered_patterns<'p, 'tcx>(
11471144
}
11481145

11491146
fn collect_non_exhaustive_tys<'tcx>(
1150-
cx: &MatchCheckCtxt<'_, 'tcx>,
1147+
cx: &PatCtxt<'_, 'tcx>,
11511148
pat: &WitnessPat<'_, 'tcx>,
11521149
non_exhaustive_tys: &mut FxIndexSet<Ty<'tcx>>,
11531150
) {

compiler/rustc_pattern_analysis/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_middle::thir::Pat;
44
use rustc_middle::ty::Ty;
55
use rustc_span::Span;
66

7-
use crate::rustc::{RustcMatchCheckCtxt, WitnessPat};
7+
use crate::rustc::{RustcPatCtxt, WitnessPat};
88

99
#[derive(Subdiagnostic)]
1010
#[label(pattern_analysis_uncovered)]
@@ -21,7 +21,7 @@ pub struct Uncovered<'tcx> {
2121
impl<'tcx> Uncovered<'tcx> {
2222
pub fn new<'p>(
2323
span: Span,
24-
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
24+
cx: &RustcPatCtxt<'p, 'tcx>,
2525
witnesses: Vec<WitnessPat<'p, 'tcx>>,
2626
) -> Self
2727
where

compiler/rustc_pattern_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'p, Cx: PatCx> Copy for MatchArm<'p, Cx> {}
173173
/// useful, and runs some lints.
174174
#[cfg(feature = "rustc")]
175175
pub fn analyze_match<'p, 'tcx>(
176-
tycx: &rustc::RustcMatchCheckCtxt<'p, 'tcx>,
176+
tycx: &rustc::RustcPatCtxt<'p, 'tcx>,
177177
arms: &[rustc::MatchArm<'p, 'tcx>],
178178
scrut_ty: Ty<'tcx>,
179179
pattern_complexity_limit: Option<usize>,

compiler/rustc_pattern_analysis/src/lints.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use rustc_span::ErrorGuaranteed;
44
use crate::constructor::Constructor;
55
use crate::errors::{NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered};
66
use crate::pat_column::PatternColumn;
7-
use crate::rustc::{RevealedTy, RustcMatchCheckCtxt, WitnessPat};
7+
use crate::rustc::{RevealedTy, RustcPatCtxt, WitnessPat};
88
use crate::MatchArm;
99

1010
/// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned
1111
/// in a given column.
1212
#[instrument(level = "debug", skip(cx), ret)]
1313
fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
14-
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
15-
column: &PatternColumn<'p, RustcMatchCheckCtxt<'p, 'tcx>>,
14+
cx: &RustcPatCtxt<'p, 'tcx>,
15+
column: &PatternColumn<'p, RustcPatCtxt<'p, 'tcx>>,
1616
) -> Result<Vec<WitnessPat<'p, 'tcx>>, ErrorGuaranteed> {
1717
let Some(&ty) = column.head_ty() else {
1818
return Ok(Vec::new());
@@ -57,9 +57,9 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
5757
}
5858

5959
pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
60-
rcx: &RustcMatchCheckCtxt<'p, 'tcx>,
61-
arms: &[MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>],
62-
pat_column: &PatternColumn<'p, RustcMatchCheckCtxt<'p, 'tcx>>,
60+
rcx: &RustcPatCtxt<'p, 'tcx>,
61+
arms: &[MatchArm<'p, RustcPatCtxt<'p, 'tcx>>],
62+
pat_column: &PatternColumn<'p, RustcPatCtxt<'p, 'tcx>>,
6363
scrut_ty: RevealedTy<'tcx>,
6464
) -> Result<(), ErrorGuaranteed> {
6565
if !matches!(

compiler/rustc_pattern_analysis/src/rustc.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ use crate::{errors, Captures, PatCx, PrivateUninhabitedField};
2323
use crate::constructor::Constructor::*;
2424

2525
// Re-export rustc-specific versions of all these types.
26-
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcMatchCheckCtxt<'p, 'tcx>>;
27-
pub type ConstructorSet<'p, 'tcx> =
28-
crate::constructor::ConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
29-
pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<RustcMatchCheckCtxt<'p, 'tcx>>;
30-
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
31-
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
26+
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcPatCtxt<'p, 'tcx>>;
27+
pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet<RustcPatCtxt<'p, 'tcx>>;
28+
pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<RustcPatCtxt<'p, 'tcx>>;
29+
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcPatCtxt<'p, 'tcx>>;
30+
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcPatCtxt<'p, 'tcx>>;
3231
pub type UsefulnessReport<'p, 'tcx> =
33-
crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
34-
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcMatchCheckCtxt<'p, 'tcx>>;
32+
crate::usefulness::UsefulnessReport<'p, RustcPatCtxt<'p, 'tcx>>;
33+
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcPatCtxt<'p, 'tcx>>;
3534

3635
/// A type which has gone through `cx.reveal_opaque_ty`, i.e. if it was opaque it was replaced by
3736
/// the hidden type if allowed in the current body. This ensures we consistently inspect the hidden
@@ -62,7 +61,7 @@ impl<'tcx> RevealedTy<'tcx> {
6261
}
6362

6463
#[derive(Clone)]
65-
pub struct RustcMatchCheckCtxt<'p, 'tcx: 'p> {
64+
pub struct RustcPatCtxt<'p, 'tcx: 'p> {
6665
pub tcx: TyCtxt<'tcx>,
6766
pub typeck_results: &'tcx ty::TypeckResults<'tcx>,
6867
/// The module in which the match occurs. This is necessary for
@@ -87,22 +86,19 @@ pub struct RustcMatchCheckCtxt<'p, 'tcx: 'p> {
8786
pub known_valid_scrutinee: bool,
8887
}
8988

90-
impl<'p, 'tcx: 'p> fmt::Debug for RustcMatchCheckCtxt<'p, 'tcx> {
89+
impl<'p, 'tcx: 'p> fmt::Debug for RustcPatCtxt<'p, 'tcx> {
9190
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
92-
f.debug_struct("RustcMatchCheckCtxt").finish()
91+
f.debug_struct("RustcPatCtxt").finish()
9392
}
9493
}
9594

96-
impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
95+
impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
9796
/// Type inference occasionally gives us opaque types in places where corresponding patterns
9897
/// have more specific types. To avoid inconsistencies as well as detect opaque uninhabited
9998
/// types, we use the corresponding concrete type if possible.
10099
#[inline]
101100
pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> {
102-
fn reveal_inner<'tcx>(
103-
cx: &RustcMatchCheckCtxt<'_, 'tcx>,
104-
ty: Ty<'tcx>,
105-
) -> RevealedTy<'tcx> {
101+
fn reveal_inner<'tcx>(cx: &RustcPatCtxt<'_, 'tcx>, ty: Ty<'tcx>) -> RevealedTy<'tcx> {
106102
let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!() };
107103
if let Some(local_def_id) = alias_ty.def_id.as_local() {
108104
let key = ty::OpaqueTypeKey { def_id: local_def_id, args: alias_ty.args };
@@ -199,7 +195,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
199195
+ ExactSizeIterator
200196
+ Captures<'a> {
201197
fn reveal_and_alloc<'a, 'tcx>(
202-
cx: &'a RustcMatchCheckCtxt<'_, 'tcx>,
198+
cx: &'a RustcPatCtxt<'_, 'tcx>,
203199
iter: impl Iterator<Item = Ty<'tcx>>,
204200
) -> &'a [(RevealedTy<'tcx>, PrivateUninhabitedField)] {
205201
cx.dropless_arena.alloc_from_iter(
@@ -218,7 +214,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
218214
reveal_and_alloc(cx, once(args.type_at(0)))
219215
} else {
220216
let variant =
221-
&adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
217+
&adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, *adt));
222218

223219
// In the cases of either a `#[non_exhaustive]` field list or a non-public
224220
// field, we skip uninhabited fields in order not to reveal the
@@ -270,7 +266,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
270266
// patterns. If we're here we can assume this is a box pattern.
271267
1
272268
} else {
273-
let variant_idx = RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt);
269+
let variant_idx = RustcPatCtxt::variant_index_for_adt(&ctor, *adt);
274270
adt.variant(variant_idx).fields.len()
275271
}
276272
}
@@ -506,7 +502,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
506502
_ => bug!(),
507503
};
508504
let variant =
509-
&adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
505+
&adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, *adt));
510506
arity = variant.fields.len();
511507
fields = subpatterns
512508
.iter()
@@ -774,8 +770,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
774770
PatKind::Deref { subpattern: subpatterns.next().unwrap() }
775771
}
776772
ty::Adt(adt_def, args) => {
777-
let variant_index =
778-
RustcMatchCheckCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
773+
let variant_index = RustcPatCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
779774
let subpatterns = subpatterns
780775
.enumerate()
781776
.map(|(i, pattern)| FieldPat { field: FieldIdx::new(i), pattern })
@@ -843,7 +838,7 @@ impl<'p, 'tcx: 'p> RustcMatchCheckCtxt<'p, 'tcx> {
843838
}
844839
}
845840

846-
impl<'p, 'tcx: 'p> PatCx for RustcMatchCheckCtxt<'p, 'tcx> {
841+
impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> {
847842
type Ty = RevealedTy<'tcx>;
848843
type Error = ErrorGuaranteed;
849844
type VariantIdx = VariantIdx;

0 commit comments

Comments
 (0)