diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2023-12-26 13:21:35 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-01-01 23:10:03 +0100 |
| commit | c35272058dfb9d93df35069c2ec55d2b7ce491b4 (patch) | |
| tree | 0a84b033043cfc02aab0f49494622ae7aef3b677 /compiler/rustc_pattern_analysis/src/lints.rs | |
| parent | e51e98dde6a60637b6a71b8105245b629ac3fe77 (diff) | |
| download | rust-c35272058dfb9d93df35069c2ec55d2b7ce491b4.tar.gz rust-c35272058dfb9d93df35069c2ec55d2b7ce491b4.zip | |
Statically enforce revealing of opaques
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/lints.rs')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/lints.rs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/compiler/rustc_pattern_analysis/src/lints.rs b/compiler/rustc_pattern_analysis/src/lints.rs index cb712fe640c..3b1721dbc63 100644 --- a/compiler/rustc_pattern_analysis/src/lints.rs +++ b/compiler/rustc_pattern_analysis/src/lints.rs @@ -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); |
