1
- use rustc_arena:: TypedArena ;
2
1
use smallvec:: SmallVec ;
3
2
4
3
use rustc_data_structures:: captures:: Captures ;
@@ -13,8 +12,8 @@ use crate::errors::{
13
12
OverlappingRangeEndpoints , Uncovered ,
14
13
} ;
15
14
use crate :: rustc:: {
16
- Constructor , DeconstructedPat , MatchArm , PlaceCtxt , RustcMatchCheckCtxt , SplitConstructorSet ,
17
- WitnessPat ,
15
+ Constructor , DeconstructedPat , MatchArm , MatchCtxt , PlaceCtxt , RustcMatchCheckCtxt ,
16
+ SplitConstructorSet , WitnessPat ,
18
17
} ;
19
18
use crate :: MatchCx ;
20
19
@@ -70,7 +69,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
70
69
/// Do constructor splitting on the constructors of the column.
71
70
fn analyze_ctors ( & self , pcx : & PlaceCtxt < ' _ , ' p , ' tcx > ) -> SplitConstructorSet < ' p , ' tcx > {
72
71
let column_ctors = self . patterns . iter ( ) . map ( |p| p. ctor ( ) ) ;
73
- pcx. cx . ctors_for_ty ( pcx . ty ) . split ( pcx, column_ctors)
72
+ pcx. ctors_for_ty ( ) . split ( pcx, column_ctors)
74
73
}
75
74
76
75
fn iter < ' b > ( & ' b self ) -> impl Iterator < Item = & ' a DeconstructedPat < ' p , ' tcx > > + Captures < ' b > {
@@ -121,16 +120,15 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
121
120
122
121
/// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned
123
122
/// in a given column.
124
- #[ instrument( level = "debug" , skip( cx, wildcard_arena ) , ret) ]
123
+ #[ instrument( level = "debug" , skip( cx) , ret) ]
125
124
fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
126
- cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
125
+ cx : MatchCtxt < ' a , ' p , ' tcx > ,
127
126
column : & PatternColumn < ' a , ' p , ' tcx > ,
128
- wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
129
127
) -> Vec < WitnessPat < ' p , ' tcx > > {
130
128
let Some ( ty) = column. head_ty ( ) else {
131
129
return Vec :: new ( ) ;
132
130
} ;
133
- let pcx = & PlaceCtxt :: new_dummy ( cx, ty, wildcard_arena ) ;
131
+ let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
134
132
135
133
let set = column. analyze_ctors ( pcx) ;
136
134
if set. present . is_empty ( ) {
@@ -141,7 +139,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
141
139
}
142
140
143
141
let mut witnesses = Vec :: new ( ) ;
144
- if cx. is_foreign_non_exhaustive_enum ( ty) {
142
+ if cx. tycx . is_foreign_non_exhaustive_enum ( ty) {
145
143
witnesses. extend (
146
144
set. missing
147
145
. into_iter ( )
@@ -157,7 +155,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
157
155
let wild_pat = WitnessPat :: wild_from_ctor ( pcx, ctor) ;
158
156
for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
159
157
// Compute witnesses for each column.
160
- let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i, wildcard_arena ) ;
158
+ let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ;
161
159
// For each witness, we build a new pattern in the shape of `ctor(_, _, wit, _, _)`,
162
160
// adding enough wildcards to match `arity`.
163
161
for wit in wits_for_col_i {
@@ -171,29 +169,29 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
171
169
}
172
170
173
171
pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
174
- cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
172
+ cx : MatchCtxt < ' a , ' p , ' tcx > ,
175
173
arms : & [ MatchArm < ' p , ' tcx > ] ,
176
174
pat_column : & PatternColumn < ' a , ' p , ' tcx > ,
177
175
scrut_ty : Ty < ' tcx > ,
178
- wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
179
176
) {
177
+ let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
180
178
if !matches ! (
181
- cx . tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , cx . match_lint_level) . 0 ,
179
+ rcx . tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , rcx . match_lint_level) . 0 ,
182
180
rustc_session:: lint:: Level :: Allow
183
181
) {
184
- let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column, wildcard_arena ) ;
182
+ let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ;
185
183
if !witnesses. is_empty ( ) {
186
184
// Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
187
185
// is not exhaustive enough.
188
186
//
189
187
// NB: The partner lint for structs lives in `compiler/rustc_hir_analysis/src/check/pat.rs`.
190
- cx . tcx . emit_spanned_lint (
188
+ rcx . tcx . emit_spanned_lint (
191
189
NON_EXHAUSTIVE_OMITTED_PATTERNS ,
192
- cx . match_lint_level ,
193
- cx . scrut_span ,
190
+ rcx . match_lint_level ,
191
+ rcx . scrut_span ,
194
192
NonExhaustiveOmittedPattern {
195
193
scrut_ty,
196
- uncovered : Uncovered :: new ( cx . scrut_span , cx , witnesses) ,
194
+ uncovered : Uncovered :: new ( rcx . scrut_span , rcx , witnesses) ,
197
195
} ,
198
196
) ;
199
197
}
@@ -203,17 +201,17 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
203
201
// usage of the lint.
204
202
for arm in arms {
205
203
let ( lint_level, lint_level_source) =
206
- cx . tcx . lint_level_at_node ( NON_EXHAUSTIVE_OMITTED_PATTERNS , arm. arm_data ) ;
204
+ rcx . tcx . lint_level_at_node ( NON_EXHAUSTIVE_OMITTED_PATTERNS , arm. arm_data ) ;
207
205
if !matches ! ( lint_level, rustc_session:: lint:: Level :: Allow ) {
208
206
let decorator = NonExhaustiveOmittedPatternLintOnArm {
209
207
lint_span : lint_level_source. span ( ) ,
210
- suggest_lint_on_match : cx . whole_match_span . map ( |span| span. shrink_to_lo ( ) ) ,
208
+ suggest_lint_on_match : rcx . whole_match_span . map ( |span| span. shrink_to_lo ( ) ) ,
211
209
lint_level : lint_level. as_str ( ) ,
212
210
lint_name : "non_exhaustive_omitted_patterns" ,
213
211
} ;
214
212
215
213
use rustc_errors:: DecorateLint ;
216
- let mut err = cx . tcx . sess . struct_span_warn ( * arm. pat . data ( ) , "" ) ;
214
+ let mut err = rcx . tcx . sess . struct_span_warn ( * arm. pat . data ( ) , "" ) ;
217
215
err. set_primary_message ( decorator. msg ( ) ) ;
218
216
decorator. decorate_lint ( & mut err) ;
219
217
err. emit ( ) ;
@@ -223,30 +221,30 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
223
221
}
224
222
225
223
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
226
- #[ instrument( level = "debug" , skip( cx, wildcard_arena ) ) ]
224
+ #[ instrument( level = "debug" , skip( cx) ) ]
227
225
pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
228
- cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
226
+ cx : MatchCtxt < ' a , ' p , ' tcx > ,
229
227
column : & PatternColumn < ' a , ' p , ' tcx > ,
230
- wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
231
228
) {
232
229
let Some ( ty) = column. head_ty ( ) else {
233
230
return ;
234
231
} ;
235
- let pcx = & PlaceCtxt :: new_dummy ( cx, ty, wildcard_arena) ;
232
+ let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
233
+ let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
236
234
237
235
let set = column. analyze_ctors ( pcx) ;
238
236
239
237
if matches ! ( ty. kind( ) , ty:: Char | ty:: Int ( _) | ty:: Uint ( _) ) {
240
238
let emit_lint = |overlap : & IntRange , this_span : Span , overlapped_spans : & [ Span ] | {
241
- let overlap_as_pat = cx . hoist_pat_range ( overlap, ty) ;
239
+ let overlap_as_pat = rcx . hoist_pat_range ( overlap, ty) ;
242
240
let overlaps: Vec < _ > = overlapped_spans
243
241
. iter ( )
244
242
. copied ( )
245
243
. map ( |span| Overlap { range : overlap_as_pat. clone ( ) , span } )
246
244
. collect ( ) ;
247
- cx . tcx . emit_spanned_lint (
245
+ rcx . tcx . emit_spanned_lint (
248
246
lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
249
- cx . match_lint_level ,
247
+ rcx . match_lint_level ,
250
248
this_span,
251
249
OverlappingRangeEndpoints { overlap : overlaps, range : this_span } ,
252
250
) ;
@@ -291,7 +289,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
291
289
// Recurse into the fields.
292
290
for ctor in set. present {
293
291
for col in column. specialize ( pcx, & ctor) {
294
- lint_overlapping_range_endpoints ( cx, & col, wildcard_arena ) ;
292
+ lint_overlapping_range_endpoints ( cx, & col) ;
295
293
}
296
294
}
297
295
}
0 commit comments