11use rustc_session:: lint:: builtin:: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
22use rustc_span:: ErrorGuaranteed ;
33
4+ use crate :: constructor:: { Constructor , SplitConstructorSet } ;
45use 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) ]
9794fn 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
144141pub ( 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 ;
0 commit comments