Statically enforce revealing of opaques
This commit is contained in:
parent
e51e98dde6
commit
c35272058d
5 changed files with 132 additions and 94 deletions
|
@ -1,7 +1,7 @@
|
|||
use smallvec::SmallVec;
|
||||
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::lint;
|
||||
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
|
||||
use rustc_span::Span;
|
||||
|
@ -12,10 +12,9 @@ use crate::errors::{
|
|||
OverlappingRangeEndpoints, Uncovered,
|
||||
};
|
||||
use crate::rustc::{
|
||||
Constructor, DeconstructedPat, MatchArm, MatchCtxt, PlaceCtxt, RustcMatchCheckCtxt,
|
||||
Constructor, DeconstructedPat, MatchArm, MatchCtxt, PlaceCtxt, RevealedTy, RustcMatchCheckCtxt,
|
||||
SplitConstructorSet, WitnessPat,
|
||||
};
|
||||
use crate::TypeCx;
|
||||
|
||||
/// A column of patterns in the matrix, where a column is the intuitive notion of "subpatterns that
|
||||
/// inspect the same subvalue/place".
|
||||
|
@ -48,14 +47,8 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
|
|||
fn is_empty(&self) -> bool {
|
||||
self.patterns.is_empty()
|
||||
}
|
||||
fn head_ty(&self, cx: MatchCtxt<'_, 'p, 'tcx>) -> Option<Ty<'tcx>> {
|
||||
if self.patterns.len() == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let ty = self.patterns[0].ty();
|
||||
// FIXME(Nadrieril): `Cx` should only give us revealed types.
|
||||
Some(cx.tycx.reveal_opaque_ty(ty))
|
||||
fn head_ty(&self) -> Option<RevealedTy<'tcx>> {
|
||||
self.patterns.first().map(|pat| pat.ty())
|
||||
}
|
||||
|
||||
/// Do constructor splitting on the constructors of the column.
|
||||
|
@ -117,7 +110,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
|||
cx: MatchCtxt<'a, 'p, 'tcx>,
|
||||
column: &PatternColumn<'p, 'tcx>,
|
||||
) -> Vec<WitnessPat<'p, 'tcx>> {
|
||||
let Some(ty) = column.head_ty(cx) else {
|
||||
let Some(ty) = column.head_ty() else {
|
||||
return Vec::new();
|
||||
};
|
||||
let pcx = &PlaceCtxt::new_dummy(cx, ty);
|
||||
|
@ -164,7 +157,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
|||
cx: MatchCtxt<'a, 'p, 'tcx>,
|
||||
arms: &[MatchArm<'p, 'tcx>],
|
||||
pat_column: &PatternColumn<'p, 'tcx>,
|
||||
scrut_ty: Ty<'tcx>,
|
||||
scrut_ty: RevealedTy<'tcx>,
|
||||
) {
|
||||
let rcx: &RustcMatchCheckCtxt<'_, '_> = cx.tycx;
|
||||
if !matches!(
|
||||
|
@ -182,7 +175,7 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
|
|||
rcx.match_lint_level,
|
||||
rcx.scrut_span,
|
||||
NonExhaustiveOmittedPattern {
|
||||
scrut_ty,
|
||||
scrut_ty: scrut_ty.inner(),
|
||||
uncovered: Uncovered::new(rcx.scrut_span, rcx, witnesses),
|
||||
},
|
||||
);
|
||||
|
@ -218,7 +211,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
|
|||
cx: MatchCtxt<'a, 'p, 'tcx>,
|
||||
column: &PatternColumn<'p, 'tcx>,
|
||||
) {
|
||||
let Some(ty) = column.head_ty(cx) else {
|
||||
let Some(ty) = column.head_ty() else {
|
||||
return;
|
||||
};
|
||||
let pcx = &PlaceCtxt::new_dummy(cx, ty);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue