1+ use rustc_arena:: TypedArena ;
12use smallvec:: SmallVec ;
23
34use rustc_data_structures:: captures:: Captures ;
@@ -27,11 +28,11 @@ use crate::MatchArm;
2728///
2829/// This is not used in the main algorithm; only in lints.
2930#[ derive( Debug ) ]
30- pub ( crate ) struct PatternColumn < ' p , ' tcx > {
31- patterns : Vec < & ' p DeconstructedPat < ' p , ' tcx > > ,
31+ pub ( crate ) struct PatternColumn < ' a , ' p , ' tcx > {
32+ patterns : Vec < & ' a DeconstructedPat < ' p , ' tcx > > ,
3233}
3334
34- impl < ' p , ' tcx > PatternColumn < ' p , ' tcx > {
35+ impl < ' a , ' p , ' tcx > PatternColumn < ' a , ' p , ' tcx > {
3536 pub ( crate ) fn new ( arms : & [ MatchArm < ' p , ' tcx > ] ) -> Self {
3637 let mut patterns = Vec :: with_capacity ( arms. len ( ) ) ;
3738 for arm in arms {
@@ -71,7 +72,7 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
7172 pcx. cx . ctors_for_ty ( pcx. ty ) . split ( pcx, column_ctors)
7273 }
7374
74- fn iter < ' a > ( & ' a self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , ' tcx > > + Captures < ' a > {
75+ fn iter < ' b > ( & ' b self ) -> impl Iterator < Item = & ' a DeconstructedPat < ' p , ' tcx > > + Captures < ' b > {
7576 self . patterns . iter ( ) . copied ( )
7677 }
7778
@@ -80,7 +81,14 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
8081 /// This returns one column per field of the constructor. They usually all have the same length
8182 /// (the number of patterns in `self` that matched `ctor`), except that we expand or-patterns
8283 /// which may change the lengths.
83- fn specialize ( & self , pcx : & PatCtxt < ' _ , ' p , ' tcx > , ctor : & Constructor < ' tcx > ) -> Vec < Self > {
84+ fn specialize < ' b > (
85+ & self ,
86+ pcx : & ' b PatCtxt < ' _ , ' p , ' tcx > ,
87+ ctor : & Constructor < ' tcx > ,
88+ ) -> Vec < PatternColumn < ' b , ' p , ' tcx > >
89+ where
90+ ' a : ' b ,
91+ {
8492 let arity = ctor. arity ( pcx) ;
8593 if arity == 0 {
8694 return Vec :: new ( ) ;
@@ -115,15 +123,16 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
115123
116124/// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned
117125/// in a given column.
118- #[ instrument( level = "debug" , skip( cx) , ret) ]
119- fn collect_nonexhaustive_missing_variants < ' p , ' tcx > (
126+ #[ instrument( level = "debug" , skip( cx, wildcard_arena ) , ret) ]
127+ fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
120128 cx : & MatchCheckCtxt < ' p , ' tcx > ,
121- column : & PatternColumn < ' p , ' tcx > ,
129+ column : & PatternColumn < ' a , ' p , ' tcx > ,
130+ wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
122131) -> Vec < WitnessPat < ' tcx > > {
123132 let Some ( ty) = column. head_ty ( ) else {
124133 return Vec :: new ( ) ;
125134 } ;
126- let pcx = & PatCtxt :: new_dummy ( cx, ty) ;
135+ let pcx = & PatCtxt :: new_dummy ( cx, ty, wildcard_arena ) ;
127136
128137 let set = column. analyze_ctors ( pcx) ;
129138 if set. present . is_empty ( ) {
@@ -150,7 +159,7 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
150159 let wild_pat = WitnessPat :: wild_from_ctor ( pcx, ctor) ;
151160 for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
152161 // Compute witnesses for each column.
153- let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ;
162+ let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i, wildcard_arena ) ;
154163 // For each witness, we build a new pattern in the shape of `ctor(_, _, wit, _, _)`,
155164 // adding enough wildcards to match `arity`.
156165 for wit in wits_for_col_i {
@@ -163,17 +172,18 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
163172 witnesses
164173}
165174
166- pub ( crate ) fn lint_nonexhaustive_missing_variants < ' p , ' tcx > (
175+ pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
167176 cx : & MatchCheckCtxt < ' p , ' tcx > ,
168177 arms : & [ MatchArm < ' p , ' tcx > ] ,
169- pat_column : & PatternColumn < ' p , ' tcx > ,
178+ pat_column : & PatternColumn < ' a , ' p , ' tcx > ,
170179 scrut_ty : Ty < ' tcx > ,
180+ wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
171181) {
172182 if !matches ! (
173183 cx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , cx. match_lint_level) . 0 ,
174184 rustc_session:: lint:: Level :: Allow
175185 ) {
176- let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ;
186+ let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column, wildcard_arena ) ;
177187 if !witnesses. is_empty ( ) {
178188 // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
179189 // is not exhaustive enough.
@@ -215,15 +225,16 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'p, 'tcx>(
215225}
216226
217227/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
218- #[ instrument( level = "debug" , skip( cx) ) ]
219- pub ( crate ) fn lint_overlapping_range_endpoints < ' p , ' tcx > (
228+ #[ instrument( level = "debug" , skip( cx, wildcard_arena ) ) ]
229+ pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
220230 cx : & MatchCheckCtxt < ' p , ' tcx > ,
221- column : & PatternColumn < ' p , ' tcx > ,
231+ column : & PatternColumn < ' a , ' p , ' tcx > ,
232+ wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
222233) {
223234 let Some ( ty) = column. head_ty ( ) else {
224235 return ;
225236 } ;
226- let pcx = & PatCtxt :: new_dummy ( cx, ty) ;
237+ let pcx = & PatCtxt :: new_dummy ( cx, ty, wildcard_arena ) ;
227238
228239 let set = column. analyze_ctors ( pcx) ;
229240
@@ -282,7 +293,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'p, 'tcx>(
282293 // Recurse into the fields.
283294 for ctor in set. present {
284295 for col in column. specialize ( pcx, & ctor) {
285- lint_overlapping_range_endpoints ( cx, & col) ;
296+ lint_overlapping_range_endpoints ( cx, & col, wildcard_arena ) ;
286297 }
287298 }
288299 }
0 commit comments