Skip to content

Commit 4371b3e

Browse files
committed
Make PatternColumn generic in Cx
1 parent cd6d8f2 commit 4371b3e

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

compiler/rustc_pattern_analysis/src/lints.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
22
use rustc_span::ErrorGuaranteed;
33

4+
use crate::constructor::{Constructor, SplitConstructorSet};
45
use crate::errors::{NonExhaustiveOmittedPattern, NonExhaustiveOmittedPatternLintOnArm, Uncovered};
5-
use crate::pat::PatOrWild;
6-
use crate::rustc::{
7-
Constructor, DeconstructedPat, MatchArm, MatchCtxt, PlaceCtxt, RevealedTy, RustcMatchCheckCtxt,
8-
SplitConstructorSet, WitnessPat,
9-
};
6+
use crate::pat::{DeconstructedPat, PatOrWild};
7+
use crate::rustc::{MatchCtxt, RevealedTy, RustcMatchCheckCtxt, WitnessPat};
8+
use crate::usefulness::PlaceCtxt;
9+
use crate::{MatchArm, TypeCx};
1010

1111
/// A column of patterns in the matrix, where a column is the intuitive notion of "subpatterns that
1212
/// inspect the same subvalue/place".
@@ -19,12 +19,12 @@ use crate::rustc::{
1919
///
2020
/// This is not used in the usefulness algorithm; only in lints.
2121
#[derive(Debug)]
22-
pub(crate) struct PatternColumn<'p, 'tcx> {
23-
patterns: Vec<&'p DeconstructedPat<'p, 'tcx>>,
22+
pub(crate) struct PatternColumn<'p, Cx: TypeCx> {
23+
patterns: Vec<&'p DeconstructedPat<'p, Cx>>,
2424
}
2525

26-
impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
27-
pub(crate) fn new(arms: &[MatchArm<'p, 'tcx>]) -> Self {
26+
impl<'p, Cx: TypeCx> PatternColumn<'p, Cx> {
27+
pub(crate) fn new(arms: &[MatchArm<'p, Cx>]) -> Self {
2828
let patterns = Vec::with_capacity(arms.len());
2929
let mut column = PatternColumn { patterns };
3030
for arm in arms {
@@ -34,7 +34,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
3434
}
3535
/// Pushes a pattern onto the column, expanding any or-patterns into its subpatterns.
3636
/// Internal method, prefer [`PatternColumn::new`].
37-
fn expand_and_push(&mut self, pat: PatOrWild<'p, RustcMatchCheckCtxt<'p, 'tcx>>) {
37+
fn expand_and_push(&mut self, pat: PatOrWild<'p, Cx>) {
3838
// We flatten or-patterns and skip algorithm-generated wildcards.
3939
if pat.is_or_pat() {
4040
self.patterns.extend(
@@ -45,15 +45,12 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
4545
}
4646
}
4747

48-
fn head_ty(&self) -> Option<RevealedTy<'tcx>> {
49-
self.patterns.first().map(|pat| *pat.ty())
48+
fn head_ty(&self) -> Option<&Cx::Ty> {
49+
self.patterns.first().map(|pat| pat.ty())
5050
}
5151

5252
/// Do constructor splitting on the constructors of the column.
53-
fn analyze_ctors(
54-
&self,
55-
pcx: &PlaceCtxt<'_, 'p, 'tcx>,
56-
) -> Result<SplitConstructorSet<'p, 'tcx>, ErrorGuaranteed> {
53+
fn analyze_ctors(&self, pcx: &PlaceCtxt<'_, Cx>) -> Result<SplitConstructorSet<Cx>, Cx::Error> {
5754
let column_ctors = self.patterns.iter().map(|p| p.ctor());
5855
let ctors_for_ty = &pcx.ctors_for_ty()?;
5956
Ok(ctors_for_ty.split(column_ctors))
@@ -66,9 +63,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
6663
/// which may change the lengths.
6764
fn specialize(
6865
&self,
69-
pcx: &PlaceCtxt<'_, 'p, 'tcx>,
70-
ctor: &Constructor<'p, 'tcx>,
71-
) -> Vec<PatternColumn<'p, 'tcx>> {
66+
pcx: &PlaceCtxt<'_, Cx>,
67+
ctor: &Constructor<Cx>,
68+
) -> Vec<PatternColumn<'p, Cx>> {
7269
let arity = ctor.arity(pcx);
7370
if arity == 0 {
7471
return Vec::new();
@@ -96,9 +93,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
9693
#[instrument(level = "debug", skip(cx), ret)]
9794
fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
9895
cx: MatchCtxt<'a, 'p, 'tcx>,
99-
column: &PatternColumn<'p, 'tcx>,
96+
column: &PatternColumn<'p, RustcMatchCheckCtxt<'p, 'tcx>>,
10097
) -> Result<Vec<WitnessPat<'p, 'tcx>>, ErrorGuaranteed> {
101-
let Some(ty) = column.head_ty() else {
98+
let Some(&ty) = column.head_ty() else {
10299
return Ok(Vec::new());
103100
};
104101
let pcx = &PlaceCtxt::new_dummy(cx, &ty);
@@ -143,8 +140,8 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
143140

144141
pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
145142
cx: MatchCtxt<'a, 'p, 'tcx>,
146-
arms: &[MatchArm<'p, 'tcx>],
147-
pat_column: &PatternColumn<'p, 'tcx>,
143+
arms: &[MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>],
144+
pat_column: &PatternColumn<'p, RustcMatchCheckCtxt<'p, 'tcx>>,
148145
scrut_ty: RevealedTy<'tcx>,
149146
) -> Result<(), ErrorGuaranteed> {
150147
let rcx: &RustcMatchCheckCtxt<'_, '_> = cx.tycx;

compiler/rustc_pattern_analysis/src/rustc.rs

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ pub type DeconstructedPat<'p, 'tcx> =
3232
crate::pat::DeconstructedPat<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3333
pub type MatchArm<'p, 'tcx> = crate::MatchArm<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
3434
pub type MatchCtxt<'a, 'p, 'tcx> = crate::MatchCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
35-
pub(crate) type PlaceCtxt<'a, 'p, 'tcx> =
36-
crate::usefulness::PlaceCtxt<'a, RustcMatchCheckCtxt<'p, 'tcx>>;
37-
pub(crate) type SplitConstructorSet<'p, 'tcx> =
38-
crate::constructor::SplitConstructorSet<RustcMatchCheckCtxt<'p, 'tcx>>;
3935
pub type Usefulness<'p, 'tcx> = crate::usefulness::Usefulness<'p, RustcMatchCheckCtxt<'p, 'tcx>>;
4036
pub type UsefulnessReport<'p, 'tcx> =
4137
crate::usefulness::UsefulnessReport<'p, RustcMatchCheckCtxt<'p, 'tcx>>;

0 commit comments

Comments
 (0)