1
1
use rustc_session:: lint:: builtin:: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
2
2
use rustc_span:: ErrorGuaranteed ;
3
3
4
+ use crate :: constructor:: { Constructor , SplitConstructorSet } ;
4
5
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 } ;
10
10
11
11
/// A column of patterns in the matrix, where a column is the intuitive notion of "subpatterns that
12
12
/// inspect the same subvalue/place".
@@ -19,12 +19,12 @@ use crate::rustc::{
19
19
///
20
20
/// This is not used in the usefulness algorithm; only in lints.
21
21
#[ 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 > > ,
24
24
}
25
25
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 {
28
28
let patterns = Vec :: with_capacity ( arms. len ( ) ) ;
29
29
let mut column = PatternColumn { patterns } ;
30
30
for arm in arms {
@@ -34,7 +34,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
34
34
}
35
35
/// Pushes a pattern onto the column, expanding any or-patterns into its subpatterns.
36
36
/// 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 > ) {
38
38
// We flatten or-patterns and skip algorithm-generated wildcards.
39
39
if pat. is_or_pat ( ) {
40
40
self . patterns . extend (
@@ -45,15 +45,12 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
45
45
}
46
46
}
47
47
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 ( ) )
50
50
}
51
51
52
52
/// 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 > {
57
54
let column_ctors = self . patterns . iter ( ) . map ( |p| p. ctor ( ) ) ;
58
55
let ctors_for_ty = & pcx. ctors_for_ty ( ) ?;
59
56
Ok ( ctors_for_ty. split ( column_ctors) )
@@ -66,9 +63,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
66
63
/// which may change the lengths.
67
64
fn specialize (
68
65
& 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 > > {
72
69
let arity = ctor. arity ( pcx) ;
73
70
if arity == 0 {
74
71
return Vec :: new ( ) ;
@@ -96,9 +93,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
96
93
#[ instrument( level = "debug" , skip( cx) , ret) ]
97
94
fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
98
95
cx : MatchCtxt < ' a , ' p , ' tcx > ,
99
- column : & PatternColumn < ' p , ' tcx > ,
96
+ column : & PatternColumn < ' p , RustcMatchCheckCtxt < ' p , ' tcx > > ,
100
97
) -> Result < Vec < WitnessPat < ' p , ' tcx > > , ErrorGuaranteed > {
101
- let Some ( ty) = column. head_ty ( ) else {
98
+ let Some ( & ty) = column. head_ty ( ) else {
102
99
return Ok ( Vec :: new ( ) ) ;
103
100
} ;
104
101
let pcx = & PlaceCtxt :: new_dummy ( cx, & ty) ;
@@ -143,8 +140,8 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
143
140
144
141
pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
145
142
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 > > ,
148
145
scrut_ty : RevealedTy < ' tcx > ,
149
146
) -> Result < ( ) , ErrorGuaranteed > {
150
147
let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
0 commit comments