diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2023-12-14 17:54:11 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2023-12-15 16:58:38 +0100 |
| commit | e10b1657758e39668c0fd93c9a0d3f32d0a7c0a7 (patch) | |
| tree | 3e9752b6a0a71f6bb82f78e36f448e75b6fe8542 /compiler/rustc_pattern_analysis/src | |
| parent | 63c5b008e12355615a3dfe5b4c83b9a109b2bbc6 (diff) | |
| download | rust-e10b1657758e39668c0fd93c9a0d3f32d0a7c0a7.tar.gz rust-e10b1657758e39668c0fd93c9a0d3f32d0a7c0a7.zip | |
s/RustcCtxt/RustcMatchCheckCtxt/
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/errors.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lib.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lints.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/rustc.rs | 57 |
4 files changed, 44 insertions, 34 deletions
diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index 8585e6da3cd..88770b0c43b 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -4,7 +4,7 @@ use rustc_middle::thir::Pat; use rustc_middle::ty::Ty; use rustc_span::Span; -use crate::rustc::{RustcCtxt, WitnessPat}; +use crate::rustc::{RustcMatchCheckCtxt, WitnessPat}; #[derive(Subdiagnostic)] #[label(pattern_analysis_uncovered)] @@ -21,7 +21,7 @@ pub struct Uncovered<'tcx> { impl<'tcx> Uncovered<'tcx> { pub fn new<'p>( span: Span, - cx: &RustcCtxt<'p, 'tcx>, + cx: &RustcMatchCheckCtxt<'p, 'tcx>, witnesses: Vec<WitnessPat<'p, 'tcx>>, ) -> Self { let witness_1 = cx.hoist_witness_pat(witnesses.get(0).unwrap()); diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index e54f8d90d0d..3e2599858af 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -32,7 +32,7 @@ use crate::lints::{ }; use crate::pat::DeconstructedPat; #[cfg(feature = "rustc")] -use crate::rustc::RustcCtxt; +use crate::rustc::RustcMatchCheckCtxt; #[cfg(feature = "rustc")] use crate::usefulness::{compute_match_usefulness, ValidityConstraint}; @@ -90,7 +90,7 @@ pub use rustc_data_structures::captures::Captures; /// useful, and runs some lints. #[cfg(feature = "rustc")] pub fn analyze_match<'p, 'tcx>( - cx: &RustcCtxt<'p, 'tcx>, + cx: &RustcMatchCheckCtxt<'p, 'tcx>, arms: &[rustc::MatchArm<'p, 'tcx>], scrut_ty: Ty<'tcx>, ) -> rustc::UsefulnessReport<'p, 'tcx> { diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index be12c8dbd7d..38108b62d79 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -13,7 +13,8 @@ use crate::errors::{ OverlappingRangeEndpoints, Uncovered, }; use crate::rustc::{ - Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcCtxt, SplitConstructorSet, WitnessPat, + Constructor, DeconstructedPat, MatchArm, PatCtxt, RustcMatchCheckCtxt, SplitConstructorSet, + WitnessPat, }; use crate::MatchCx; @@ -55,10 +56,10 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> { // If the type is opaque and it is revealed anywhere in the column, we take the revealed // version. Otherwise we could encounter constructors for the revealed type and crash. let first_ty = self.patterns[0].ty(); - if RustcCtxt::is_opaque_ty(first_ty) { + if RustcMatchCheckCtxt::is_opaque_ty(first_ty) { for pat in &self.patterns { let ty = pat.ty(); - if !RustcCtxt::is_opaque_ty(ty) { + if !RustcMatchCheckCtxt::is_opaque_ty(ty) { return Some(ty); } } @@ -125,7 +126,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> { /// in a given column. #[instrument(level = "debug", skip(cx, wildcard_arena), ret)] fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>( - cx: &RustcCtxt<'p, 'tcx>, + cx: &RustcMatchCheckCtxt<'p, 'tcx>, column: &PatternColumn<'a, 'p, 'tcx>, wildcard_arena: &TypedArena<DeconstructedPat<'p, 'tcx>>, ) -> Vec<WitnessPat<'p, 'tcx>> { @@ -173,7 +174,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>( } pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>( - cx: &RustcCtxt<'p, 'tcx>, + cx: &RustcMatchCheckCtxt<'p, 'tcx>, arms: &[MatchArm<'p, 'tcx>], pat_column: &PatternColumn<'a, 'p, 'tcx>, scrut_ty: Ty<'tcx>, @@ -227,7 +228,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>( /// Traverse the patterns to warn the user about ranges that overlap on their endpoints. #[instrument(level = "debug", skip(cx, wildcard_arena))] pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>( - cx: &RustcCtxt<'p, 'tcx>, + cx: &RustcMatchCheckCtxt<'p, 'tcx>, column: &PatternColumn<'a, 'p, 'tcx>, wildcard_arena: &TypedArena<DeconstructedPat<'p, 'tcx>>, ) { diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index 4b13c11d29e..1d08d2efef3 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -25,19 +25,23 @@ use crate::MatchCx; use crate::constructor::Constructor::*; // Re-export rustc-specific versions of all these types. -pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcCtxt<'p, 'tcx>>; -pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet<RustcCtxt<'p, 'tcx>>; -pub type DeconstructedPat<'p, 'tcx> = crate::pat::DeconstructedPat<'p, RustcCtxt<'p, 'tcx>>; -pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcCtxt<'p, 'tcx>>; -pub(crate) type PatCtxt<'a, 'p, 'tcx> = crate::usefulness::PatCtxt<'a, 'p, RustcCtxt<'p, 'tcx>>; +pub type Constructor<'p, 'tcx> = crate::constructor::Constructor<RustcMatchCheckCtxt<'p, 'tcx>>; +pub type ConstructorSet<'p, 'tcx> = + crate::constructor::ConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>; +pub type DeconstructedPat<'p, 'tcx> = + crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>; +pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>; +pub(crate) type PatCtxt<'a, 'p, 'tcx> = + crate::usefulness::PatCtxt<'a, 'p, RustcMatchCheckCtxt<'p, 'tcx>>; pub(crate) type SplitConstructorSet<'p, 'tcx> = - crate::constructor::SplitConstructorSet<RustcCtxt<'p, 'tcx>>; + crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>; pub type Usefulness = crate::usefulness::Usefulness<Span>; -pub type UsefulnessReport<'p, 'tcx> = crate::usefulness::UsefulnessReport<'p, RustcCtxt<'p, 'tcx>>; -pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcCtxt<'p, 'tcx>>; +pub type UsefulnessReport<'p, 'tcx> = + crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'tcx>>; +pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat<RustcMatchCheckCtxt<'p, 'tcx>>; #[derive(Clone)] -pub struct RustcCtxt<'p, 'tcx> { +pub struct RustcMatchCheckCtxt<'p, 'tcx> { pub tcx: TyCtxt<'tcx>, /// The module in which the match occurs. This is necessary for /// checking inhabited-ness of types because whether a type is (visibly) @@ -61,13 +65,13 @@ pub struct RustcCtxt<'p, 'tcx> { pub known_valid_scrutinee: bool, } -impl<'p, 'tcx> fmt::Debug for RustcCtxt<'p, 'tcx> { +impl<'p, 'tcx> fmt::Debug for RustcMatchCheckCtxt<'p, 'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("RustcCtxt").finish() + f.debug_struct("RustcMatchCheckCtxt").finish() } } -impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { +impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> { pub(crate) fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool { !ty.is_inhabited_from(self.tcx, self.module, self.param_env) } @@ -152,7 +156,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { // patterns. If we're here we can assume this is a box pattern. cx.dropless_arena.alloc_from_iter(once(args.type_at(0))) } else { - let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt)); + let variant = + &adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt)); let tys = cx.list_variant_nonhidden_fields(ty, variant).map(|(_, ty)| ty); cx.dropless_arena.alloc_from_iter(tys) } @@ -197,7 +202,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { // patterns. If we're here we can assume this is a box pattern. 1 } else { - let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt)); + let variant = + &adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt)); self.list_variant_nonhidden_fields(ty, variant).count() } } @@ -428,7 +434,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { PatKind::Variant { variant_index, .. } => Variant(variant_index), _ => bug!(), }; - let variant = &adt.variant(RustcCtxt::variant_index_for_adt(&ctor, *adt)); + let variant = + &adt.variant(RustcMatchCheckCtxt::variant_index_for_adt(&ctor, *adt)); // For each field in the variant, we store the relevant index into `self.fields` if any. let mut field_id_to_id: Vec<Option<usize>> = (0..variant.fields.len()).map(|_| None).collect(); @@ -687,7 +694,8 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { PatKind::Deref { subpattern: subpatterns.next().unwrap() } } ty::Adt(adt_def, args) => { - let variant_index = RustcCtxt::variant_index_for_adt(&pat.ctor(), *adt_def); + let variant_index = + RustcMatchCheckCtxt::variant_index_for_adt(&pat.ctor(), *adt_def); let variant = &adt_def.variant(variant_index); let subpatterns = cx .list_variant_nonhidden_fields(pat.ty(), variant) @@ -782,13 +790,14 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { write!(f, "box {subpattern:?}") } ty::Adt(..) | ty::Tuple(..) => { - let variant = match pat.ty().kind() { - ty::Adt(adt, _) => { - Some(adt.variant(RustcCtxt::variant_index_for_adt(pat.ctor(), *adt))) - } - ty::Tuple(_) => None, - _ => unreachable!(), - }; + let variant = + match pat.ty().kind() { + ty::Adt(adt, _) => Some(adt.variant( + RustcMatchCheckCtxt::variant_index_for_adt(pat.ctor(), *adt), + )), + ty::Tuple(_) => None, + _ => unreachable!(), + }; if let Some(variant) = variant { write!(f, "{}", variant.name)?; @@ -853,7 +862,7 @@ impl<'p, 'tcx> RustcCtxt<'p, 'tcx> { } } -impl<'p, 'tcx> MatchCx for RustcCtxt<'p, 'tcx> { +impl<'p, 'tcx> MatchCx for RustcMatchCheckCtxt<'p, 'tcx> { type Ty = Ty<'tcx>; type Span = Span; type VariantIdx = VariantIdx; |
