Skip to content

Commit 44cd4d1

Browse files
committed
s/RustcCtxt/RustcMatchCheckCtxt/
1 parent 5d7b823 commit 44cd4d1

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
lines changed

compiler/rustc_mir_build/src/errors.rs

Lines changed: 2 additions & 2 deletions
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::RustcCtxt};
9+
use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcMatchCheckCtxt};
1010
use rustc_span::symbol::Symbol;
1111
use rustc_span::Span;
1212

@@ -454,7 +454,7 @@ pub enum UnusedUnsafeEnclosing {
454454
}
455455

456456
pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> {
457-
pub cx: &'m RustcCtxt<'p, 'tcx>,
457+
pub cx: &'m RustcMatchCheckCtxt<'p, 'tcx>,
458458
pub expr_span: Span,
459459
pub span: Span,
460460
pub ty: Ty<'tcx>,

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

Lines changed: 2 additions & 2 deletions
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, RustcCtxt as MatchCheckCtxt, Usefulness, UsefulnessReport,
4-
WitnessPat,
3+
Constructor, DeconstructedPat, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness,
4+
UsefulnessReport, WitnessPat,
55
};
66
use rustc_pattern_analysis::{analyze_match, MatchArm};
77

compiler/rustc_pattern_analysis/src/errors.rs

Lines changed: 2 additions & 2 deletions
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::{RustcCtxt, WitnessPat};
7+
use crate::rustc::{RustcMatchCheckCtxt, 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: &RustcCtxt<'p, 'tcx>,
24+
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
2525
witnesses: Vec<WitnessPat<'p, 'tcx>>,
2626
) -> Self {
2727
let witness_1 = cx.hoist_witness_pat(witnesses.get(0).unwrap());

compiler/rustc_pattern_analysis/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::lints::{
3232
};
3333
use crate::pat::DeconstructedPat;
3434
#[cfg(feature = "rustc")]
35-
use crate::rustc::RustcCtxt;
35+
use crate::rustc::RustcMatchCheckCtxt;
3636
#[cfg(feature = "rustc")]
3737
use crate::usefulness::{compute_match_usefulness, ValidityConstraint};
3838

@@ -90,7 +90,7 @@ pub use rustc_data_structures::captures::Captures;
9090
/// useful, and runs some lints.
9191
#[cfg(feature = "rustc")]
9292
pub fn analyze_match<'p, 'tcx>(
93-
cx: &RustcCtxt<'p, 'tcx>,
93+
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
9494
arms: &[rustc::MatchArm<'p, 'tcx>],
9595
scrut_ty: Ty<'tcx>,
9696
) -> rustc::UsefulnessReport<'p, 'tcx> {

compiler/rustc_pattern_analysis/src/lints.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::errors::{
1313
OverlappingRangeEndpoints, Uncovered,
1414
};
1515
use crate::rustc::{
16-
Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcCtxt, SplitConstructorSet, WitnessPat,
16+
Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcMatchCheckCtxt, SplitConstructorSet,
17+
WitnessPat,
1718
};
1819
use crate::MatchCx;
1920

@@ -55,10 +56,10 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
5556
// If the type is opaque and it is revealed anywhere in the column, we take the revealed
5657
// version. Otherwise we could encounter constructors for the revealed type and crash.
5758
let first_ty = self.patterns[0].ty();
58-
if RustcCtxt::is_opaque_ty(first_ty) {
59+
if RustcMatchCheckCtxt::is_opaque_ty(first_ty) {
5960
for pat in &self.patterns {
6061
let ty = pat.ty();
61-
if !RustcCtxt::is_opaque_ty(ty) {
62+
if !RustcMatchCheckCtxt::is_opaque_ty(ty) {
6263
return Some(ty);
6364
}
6465
}
@@ -125,7 +126,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
125126
/// in a given column.
126127
#[instrument(level = "debug", skip(cx, wildcard_arena), ret)]
127128
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
128-
cx: &RustcCtxt<'p, 'tcx>,
129+
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
129130
column: &PatternColumn<'a, 'p, 'tcx>,
130131
wildcard_arena: &TypedArena<DeconstructedPat<'p, 'tcx>>,
131132
) -> Vec<WitnessPat<'p, 'tcx>> {
@@ -173,7 +174,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
173174
}
174175

175176
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
176-
cx: &RustcCtxt<'p, 'tcx>,
177+
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
177178
arms: &[MatchArm<'p, 'tcx>],
178179
pat_column: &PatternColumn<'a, 'p, 'tcx>,
179180
scrut_ty: Ty<'tcx>,
@@ -227,7 +228,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
227228
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
228229
#[instrument(level = "debug", skip(cx, wildcard_arena))]
229230
pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
230-
cx: &RustcCtxt<'p, 'tcx>,
231+
cx: &RustcMatchCheckCtxt<'p, 'tcx>,
231232
column: &PatternColumn<'a, 'p, 'tcx>,
232233
wildcard_arena: &TypedArena<DeconstructedPat<'p, 'tcx>>,
233234
) {

compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,23 @@ use crate::MatchCx;
2525
use crate::constructor::Constructor::*;
2626

2727
// Re-export rustc-specific versions of all these types.
28-
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcCtxt<'p, 'tcx>>;
29-
pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet<RustcCtxt<'p, 'tcx>>;
30-
pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<'p, RustcCtxt<'p, 'tcx>>;
31-
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcCtxt<'p, 'tcx>>;
32-
pub(crate) type PatCtxt<'a, 'p, 'tcx> = crate::usefulness::PatCtxt<'a, 'p, RustcCtxt<'p, 'tcx>>;
28+
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcMatchCheckCtxt<'p, 'tcx>>;
29+
pub type ConstructorSet<'p, 'tcx> =
30+
crate::constructor::ConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
31+
pub type DeconstructedPat<'p, 'tcx> =
32+
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
33+
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>>;
3336
pub(crate) type SplitConstructorSet<'p, 'tcx> =
34-
crate::constructor::SplitConstructorSet<RustcCtxt<'p, 'tcx>>;
37+
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
3538
pub type Usefulness = crate::usefulness::Usefulness<Span>;
36-
pub type UsefulnessReport<'p, 'tcx> = crate::usefulness::UsefulnessReport<'p, RustcCtxt<'p, 'tcx>>;
37-
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcCtxt<'p, 'tcx>>;
39+
pub type UsefulnessReport<'p, 'tcx> =
40+
crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
41+
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcMatchCheckCtxt<'p, 'tcx>>;
3842

3943
#[derive(Clone)]
40-
pub struct RustcCtxt<'p, 'tcx> {
44+
pub struct RustcMatchCheckCtxt<'p, 'tcx> {
4145
pub tcx: TyCtxt<'tcx>,
4246
/// The module in which the match occurs. This is necessary for
4347
/// checking inhabited-ness of types because whether a type is (visibly)
@@ -61,13 +65,13 @@ pub struct RustcCtxt<'p, 'tcx> {
6165
pub known_valid_scrutinee: bool,
6266
}
6367

64-
impl<'p, 'tcx> fmt::Debug for RustcCtxt<'p, 'tcx> {
68+
impl<'p, 'tcx> fmt::Debug for RustcMatchCheckCtxt<'p, 'tcx> {
6569
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66-
f.debug_struct("RustcCtxt").finish()
70+
f.debug_struct("RustcMatchCheckCtxt").finish()
6771
}
6872
}
6973

70-
impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
74+
impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
7175
pub(crate) fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
7276
!ty.is_inhabited_from(self.tcx, self.module, self.param_env)
7377
}
@@ -152,7 +156,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
152156
// patterns. If we're here we can assume this is a box pattern.
153157
cx.dropless_arena.alloc_from_iter(once(args.type_at(0)))
154158
} else {
155-
let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt));
159+
let variant =
160+
&adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
156161
let tys = cx.list_variant_nonhidden_fields(ty, variant).map(|(_, ty)| ty);
157162
cx.dropless_arena.alloc_from_iter(tys)
158163
}
@@ -197,7 +202,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
197202
// patterns. If we're here we can assume this is a box pattern.
198203
1
199204
} else {
200-
let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt));
205+
let variant =
206+
&adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
201207
self.list_variant_nonhidden_fields(ty, variant).count()
202208
}
203209
}
@@ -428,7 +434,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
428434
PatKind::Variant { variant_index, .. } => Variant(variant_index),
429435
_ => bug!(),
430436
};
431-
let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt));
437+
let variant =
438+
&adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
432439
// For each field in the variant, we store the relevant index into `self.fields` if any.
433440
let mut field_id_to_id: Vec<Option<usize>> =
434441
(0..variant.fields.len()).map(|_| None).collect();
@@ -687,7 +694,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
687694
PatKind::Deref { subpattern: subpatterns.next().unwrap() }
688695
}
689696
ty::Adt(adt_def, args) => {
690-
let variant_index = RustcCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
697+
let variant_index =
698+
RustcMatchCheckCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
691699
let variant = &adt_def.variant(variant_index);
692700
let subpatterns = cx
693701
.list_variant_nonhidden_fields(pat.ty(), variant)
@@ -782,13 +790,14 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
782790
write!(f, "box {subpattern:?}")
783791
}
784792
ty::Adt(..) | ty::Tuple(..) => {
785-
let variant = match pat.ty().kind() {
786-
ty::Adt(adt, _) => {
787-
Some(adt.variant(RustcCtxt::variant_index_for_adt(pat.ctor(), *adt)))
788-
}
789-
ty::Tuple(_) => None,
790-
_ => unreachable!(),
791-
};
793+
let variant =
794+
match pat.ty().kind() {
795+
ty::Adt(adt, _) => Some(adt.variant(
796+
RustcMatchCheckCtxt::variant_index_for_adt(pat.ctor(), *adt),
797+
)),
798+
ty::Tuple(_) => None,
799+
_ => unreachable!(),
800+
};
792801

793802
if let Some(variant) = variant {
794803
write!(f, "{}", variant.name)?;
@@ -853,7 +862,7 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
853862
}
854863
}
855864

856-
impl<'p, 'tcx> MatchCx for RustcCtxt<'p, 'tcx> {
865+
impl<'p, 'tcx> MatchCx for RustcMatchCheckCtxt<'p, 'tcx> {
857866
type Ty = Ty<'tcx>;
858867
type Span = Span;
859868
type VariantIdx = VariantIdx;

0 commit comments

Comments
 (0)