s/RustcCtxt/RustcMatchCheckCtxt/
This commit is contained in:
parent
63c5b008e1
commit
e10b165775
@ -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>,
|
||||
|
@ -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};
|
||||
|
||||
|
@ -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<WitnessPat<'p, 'tcx>>,
|
||||
) -> Self {
|
||||
let witness_1 = cx.hoist_witness_pat(witnesses.get(0).unwrap());
|
||||
|
@ -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> {
|
||||
|
@ -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<Ty<'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 @@ 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<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>>,
|
||||
) {
|
||||
|
@ -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<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 @@ 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<Option<usize>> =
|
||||
(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;
|
||||
|
Loading…
Reference in New Issue
Block a user