From e10b1657758e39668c0fd93c9a0d3f32d0a7c0a7 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 14 Dec 2023 17:54:11 +0100 Subject: [PATCH] s/RustcCtxt/RustcMatchCheckCtxt/ --- compiler/rustc_mir_build/src/errors.rs | 4 +- .../src/thir/pattern/check_match.rs | 4 +- compiler/rustc_pattern_analysis/src/errors.rs | 4 +- compiler/rustc_pattern_analysis/src/lib.rs | 4 +- compiler/rustc_pattern_analysis/src/lints.rs | 13 +++-- compiler/rustc_pattern_analysis/src/rustc.rs | 57 +++++++++++-------- 6 files changed, 48 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_mir_build/src/errors.rs b/compiler/rustc_mir_build/src/errors.rs index 6894b44dbd4..6e5cfbd4652 100644 --- a/compiler/rustc_mir_build/src/errors.rs +++ b/compiler/rustc_mir_build/src/errors.rs @@ -6,7 +6,7 @@ }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_middle::ty::{self, Ty}; -use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcCtxt}; +use rustc_pattern_analysis::{errors::Uncovered, rustc::RustcMatchCheckCtxt}; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -454,7 +454,7 @@ pub enum UnusedUnsafeEnclosing { } pub(crate) struct NonExhaustivePatternsTypeNotEmpty<'p, 'tcx, 'm> { - pub cx: &'m RustcCtxt<'p, 'tcx>, + pub cx: &'m RustcMatchCheckCtxt<'p, 'tcx>, pub expr_span: Span, pub span: Span, pub ty: Ty<'tcx>, diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 4eed289a24d..34fd10bf967 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -1,7 +1,7 @@ use rustc_pattern_analysis::errors::Uncovered; use rustc_pattern_analysis::rustc::{ - Constructor, DeconstructedPat, RustcCtxt as MatchCheckCtxt, Usefulness, UsefulnessReport, - WitnessPat, + Constructor, DeconstructedPat, RustcMatchCheckCtxt as MatchCheckCtxt, Usefulness, + UsefulnessReport, WitnessPat, }; use rustc_pattern_analysis::{analyze_match, MatchArm}; 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::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>, ) -> 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::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 @@ impl<'a, T: ?Sized> Captures<'a> for T {} /// 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 @@ 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 @@ fn head_ty(&self) -> Option> { // 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 @@ fn specialize<'b>( /// 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>, ) -> Vec> { @@ -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>, ) { 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::constructor::Constructor::*; // Re-export rustc-specific versions of all these types. -pub type Constructor<'p, 'tcx> = crate::constructor::Constructor>; -pub type ConstructorSet<'p, 'tcx> = crate::constructor::ConstructorSet>; -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>; +pub type ConstructorSet<'p, 'tcx> = + crate::constructor::ConstructorSet>; +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>; + crate::constructor::SplitConstructorSet>; pub type Usefulness = crate::usefulness::Usefulness; -pub type UsefulnessReport<'p, 'tcx> = crate::usefulness::UsefulnessReport<'p, RustcCtxt<'p, 'tcx>>; -pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat>; +pub type UsefulnessReport<'p, 'tcx> = + crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'tcx>>; +pub type WitnessPat<'p, 'tcx> = crate::pat::WitnessPat>; #[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 @@ pub(crate) fn ctor_sub_tys(&self, ctor: &Constructor<'p, 'tcx>, ty: Ty<'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 @@ pub(crate) fn ctor_arity(&self, ctor: &Constructor<'p, 'tcx>, ty: Ty<'tcx>) -> u // 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 @@ pub fn lower_pat(&self, pat: &Pat<'tcx>) -> DeconstructedPat<'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> = (0..variant.fields.len()).map(|_| None).collect(); @@ -687,7 +694,8 @@ pub fn hoist_witness_pat(&self, pat: &WitnessPat<'p, 'tcx>) -> Pat<'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 @@ pub(crate) fn debug_pat( 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 @@ pub(crate) fn debug_pat( } } -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;