Skip to content

Commit cb622f3

Browse files
committed
Name rustc-specific things "rustc"
1 parent 3d7c4df commit cb622f3

File tree

6 files changed

+42
-48
lines changed

6 files changed

+42
-48
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::{cx::MatchCheckCtxt, errors::Uncovered};
9+
use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcCtxt};
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 MatchCheckCtxt<'p, 'tcx>,
457+
pub cx: &'m RustcCtxt<'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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use rustc_pattern_analysis::cx::{
2-
Constructor, DeconstructedPat, MatchCheckCtxt, Usefulness, UsefulnessReport, WitnessPat,
3-
};
41
use rustc_pattern_analysis::errors::Uncovered;
2+
use rustc_pattern_analysis::rustc::{
3+
Constructor, DeconstructedPat, RustcCtxt as MatchCheckCtxt, Usefulness, UsefulnessReport,
4+
WitnessPat,
5+
};
56
use rustc_pattern_analysis::{analyze_match, MatchArm};
67

78
use crate::errors::*;

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::cx::{MatchCheckCtxt, WitnessPat};
7+
use crate::rustc::{RustcCtxt, 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: &MatchCheckCtxt<'p, 'tcx>,
24+
cx: &RustcCtxt<'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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Analysis of patterns, notably match exhaustiveness checking.
22
33
pub mod constructor;
4-
pub mod cx;
54
pub mod errors;
65
pub(crate) mod lints;
76
pub mod pat;
7+
pub mod rustc;
88
pub mod usefulness;
99

1010
#[macro_use]
@@ -21,11 +21,11 @@ use lints::PatternColumn;
2121
use rustc_hir::HirId;
2222
use rustc_index::Idx;
2323
use rustc_middle::ty::Ty;
24-
use usefulness::{compute_match_usefulness, UsefulnessReport, ValidityConstraint};
24+
use usefulness::{compute_match_usefulness, ValidityConstraint};
2525

26-
use crate::cx::MatchCheckCtxt;
2726
use crate::lints::{lint_nonexhaustive_missing_variants, lint_overlapping_range_endpoints};
2827
use crate::pat::DeconstructedPat;
28+
use crate::rustc::RustcCtxt;
2929

3030
pub trait MatchCx: Sized + Clone + fmt::Debug {
3131
type Ty: Copy + Clone + fmt::Debug; // FIXME: remove Copy
@@ -69,10 +69,10 @@ impl<'p, Cx: MatchCx> Copy for MatchArm<'p, Cx> {}
6969
/// The entrypoint for this crate. Computes whether a match is exhaustive and which of its arms are
7070
/// useful, and runs some lints.
7171
pub fn analyze_match<'p, 'tcx>(
72-
cx: &MatchCheckCtxt<'p, 'tcx>,
73-
arms: &[MatchArm<'p, MatchCheckCtxt<'p, 'tcx>>],
72+
cx: &RustcCtxt<'p, 'tcx>,
73+
arms: &[rustc::MatchArm<'p, 'tcx>],
7474
scrut_ty: Ty<'tcx>,
75-
) -> UsefulnessReport<'p, MatchCheckCtxt<'p, 'tcx>> {
75+
) -> rustc::UsefulnessReport<'p, 'tcx> {
7676
// Arena to store the extra wildcards we construct during analysis.
7777
let wildcard_arena = cx.pattern_arena;
7878
let pat_column = PatternColumn::new(arms);

compiler/rustc_pattern_analysis/src/lints.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
88
use rustc_span::Span;
99

1010
use crate::constructor::{IntRange, MaybeInfiniteInt};
11-
use crate::cx::{
12-
Constructor, DeconstructedPat, MatchArm, MatchCheckCtxt, PatCtxt, SplitConstructorSet,
13-
WitnessPat,
14-
};
1511
use crate::errors::{
1612
NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Overlap,
1713
OverlappingRangeEndpoints, Uncovered,
1814
};
15+
use crate::rustc::{
16+
Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcCtxt, SplitConstructorSet, WitnessPat,
17+
};
1918
use crate::MatchCx;
2019

2120
/// A column of patterns in the matrix, where a column is the intuitive notion of "subpatterns that
@@ -56,10 +55,10 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
5655
// If the type is opaque and it is revealed anywhere in the column, we take the revealed
5756
// version. Otherwise we could encounter constructors for the revealed type and crash.
5857
let first_ty = self.patterns[0].ty();
59-
if MatchCheckCtxt::is_opaque_ty(first_ty) {
58+
if RustcCtxt::is_opaque_ty(first_ty) {
6059
for pat in &self.patterns {
6160
let ty = pat.ty();
62-
if !MatchCheckCtxt::is_opaque_ty(ty) {
61+
if !RustcCtxt::is_opaque_ty(ty) {
6362
return Some(ty);
6463
}
6564
}
@@ -126,7 +125,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
126125
/// in a given column.
127126
#[instrument(level = "debug", skip(cx, wildcard_arena), ret)]
128127
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
129-
cx: &MatchCheckCtxt<'p, 'tcx>,
128+
cx: &RustcCtxt<'p, 'tcx>,
130129
column: &PatternColumn<'a, 'p, 'tcx>,
131130
wildcard_arena: &TypedArena<DeconstructedPat<'p, 'tcx>>,
132131
) -> Vec<WitnessPat<'p, 'tcx>> {
@@ -174,7 +173,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
174173
}
175174

176175
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
177-
cx: &MatchCheckCtxt<'p, 'tcx>,
176+
cx: &RustcCtxt<'p, 'tcx>,
178177
arms: &[MatchArm<'p, 'tcx>],
179178
pat_column: &PatternColumn<'a, 'p, 'tcx>,
180179
scrut_ty: Ty<'tcx>,
@@ -228,7 +227,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
228227
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
229228
#[instrument(level = "debug", skip(cx, wildcard_arena))]
230229
pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
231-
cx: &MatchCheckCtxt<'p, 'tcx>,
230+
cx: &RustcCtxt<'p, 'tcx>,
232231
column: &PatternColumn<'a, 'p, 'tcx>,
233232
wildcard_arena: &TypedArena<DeconstructedPat<'p, 'tcx>>,
234233
) {

compiler/rustc_pattern_analysis/src/cx.rs renamed to compiler/rustc_pattern_analysis/src/rustc.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,19 @@ use crate::MatchCx;
2424

2525
use crate::constructor::Constructor::*;
2626

27-
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<MatchCheckCtxt<'p, 'tcx>>;
28-
pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet<MatchCheckCtxt<'p, 'tcx>>;
29-
pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<'p, MatchCheckCtxt<'p, 'tcx>>;
30-
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, MatchCheckCtxt<'p, 'tcx>>;
31-
pub(crate) type PatCtxt<'a, 'p, 'tcx> =
32-
crate::usefulness::PatCtxt<'a, 'p, MatchCheckCtxt<'p, 'tcx>>;
27+
pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcCtxt<'p, 'tcx>>;
28+
pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet<RustcCtxt<'p, 'tcx>>;
29+
pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<'p, RustcCtxt<'p, 'tcx>>;
30+
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcCtxt<'p, 'tcx>>;
31+
pub(crate) type PatCtxt<'a, 'p, 'tcx> = crate::usefulness::PatCtxt<'a, 'p, RustcCtxt<'p, 'tcx>>;
3332
pub(crate) type SplitConstructorSet<'p, 'tcx> =
34-
crate::constructor::SplitConstructorSet<MatchCheckCtxt<'p, 'tcx>>;
33+
crate::constructor::SplitConstructorSet<RustcCtxt<'p, 'tcx>>;
3534
pub type Usefulness = crate::usefulness::Usefulness<Span>;
36-
pub type UsefulnessReport<'p, 'tcx> =
37-
crate::usefulness::UsefulnessReport<'p, MatchCheckCtxt<'p, 'tcx>>;
38-
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<MatchCheckCtxt<'p, 'tcx>>;
35+
pub type UsefulnessReport<'p, 'tcx> = crate::usefulness::UsefulnessReport<'p, RustcCtxt<'p, 'tcx>>;
36+
pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcCtxt<'p, 'tcx>>;
3937

4038
#[derive(Clone)]
41-
pub struct MatchCheckCtxt<'p, 'tcx> {
39+
pub struct RustcCtxt<'p, 'tcx> {
4240
pub tcx: TyCtxt<'tcx>,
4341
/// The module in which the match occurs. This is necessary for
4442
/// checking inhabited-ness of types because whether a type is (visibly)
@@ -62,13 +60,13 @@ pub struct MatchCheckCtxt<'p, 'tcx> {
6260
pub known_valid_scrutinee: bool,
6361
}
6462

65-
impl<'p, 'tcx> fmt::Debug for MatchCheckCtxt<'p, 'tcx> {
63+
impl<'p, 'tcx> fmt::Debug for RustcCtxt<'p, 'tcx> {
6664
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67-
f.debug_struct("MatchCheckCtxt").finish()
65+
f.debug_struct("RustcCtxt").finish()
6866
}
6967
}
7068

71-
impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
69+
impl<'p, 'tcx> RustcCtxt<'p, 'tcx> {
7270
pub(crate) fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool {
7371
!ty.is_inhabited_from(self.tcx, self.module, self.param_env)
7472
}
@@ -153,8 +151,7 @@ impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
153151
// patterns. If we're here we can assume this is a box pattern.
154152
cx.dropless_arena.alloc_from_iter(once(args.type_at(0)))
155153
} else {
156-
let variant =
157-
&adt.variant(MatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
154+
let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt));
158155
let tys = cx.list_variant_nonhidden_fields(ty, variant).map(|(_, ty)| ty);
159156
cx.dropless_arena.alloc_from_iter(tys)
160157
}
@@ -199,8 +196,7 @@ impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
199196
// patterns. If we're here we can assume this is a box pattern.
200197
1
201198
} else {
202-
let variant =
203-
&adt.variant(MatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
199+
let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt));
204200
self.list_variant_nonhidden_fields(ty, variant).count()
205201
}
206202
}
@@ -431,8 +427,7 @@ impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
431427
PatKind::Variant { variant_index, .. } => Variant(variant_index),
432428
_ => bug!(),
433429
};
434-
let variant =
435-
&adt.variant(MatchCheckCtxt::variant_index_for_adt(&ctor, *adt));
430+
let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt));
436431
// For each field in the variant, we store the relevant index into `self.fields` if any.
437432
let mut field_id_to_id: Vec<Option<usize>> =
438433
(0..variant.fields.len()).map(|_| None).collect();
@@ -687,8 +682,7 @@ impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
687682
PatKind::Deref { subpattern: subpatterns.next().unwrap() }
688683
}
689684
ty::Adt(adt_def, args) => {
690-
let variant_index =
691-
MatchCheckCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
685+
let variant_index = RustcCtxt::variant_index_for_adt(&pat.ctor(), *adt_def);
692686
let variant = &adt_def.variant(variant_index);
693687
let subpatterns = cx
694688
.list_variant_nonhidden_fields(pat.ty(), variant)
@@ -784,9 +778,9 @@ impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
784778
}
785779
ty::Adt(..) | ty::Tuple(..) => {
786780
let variant = match pat.ty().kind() {
787-
ty::Adt(adt, _) => Some(
788-
adt.variant(MatchCheckCtxt::variant_index_for_adt(pat.ctor(), *adt)),
789-
),
781+
ty::Adt(adt, _) => {
782+
Some(adt.variant(RustcCtxt::variant_index_for_adt(pat.ctor(), *adt)))
783+
}
790784
ty::Tuple(_) => None,
791785
_ => unreachable!(),
792786
};
@@ -854,7 +848,7 @@ impl<'p, 'tcx> MatchCheckCtxt<'p, 'tcx> {
854848
}
855849
}
856850

857-
impl<'p, 'tcx> MatchCx for MatchCheckCtxt<'p, 'tcx> {
851+
impl<'p, 'tcx> MatchCx for RustcCtxt<'p, 'tcx> {
858852
type Ty = Ty<'tcx>;
859853
type Span = Span;
860854
type VariantIdx = VariantIdx;

0 commit comments

Comments
 (0)