1- use rustc_arena:: TypedArena ;
21use smallvec:: SmallVec ;
32
43use rustc_data_structures:: captures:: Captures ;
@@ -13,8 +12,8 @@ use crate::errors::{
1312 OverlappingRangeEndpoints , Uncovered ,
1413} ;
1514use crate :: rustc:: {
16- Constructor , DeconstructedPat , MatchArm , PlaceCtxt , RustcMatchCheckCtxt , SplitConstructorSet ,
17- WitnessPat ,
15+ Constructor , DeconstructedPat , MatchArm , MatchCtxt , PlaceCtxt , RustcMatchCheckCtxt ,
16+ SplitConstructorSet , WitnessPat ,
1817} ;
1918use crate :: MatchCx ;
2019
@@ -70,7 +69,7 @@ impl<'a, 'p, 'tcx> PatternColumn<'a, 'p, 'tcx> {
7069 /// Do constructor splitting on the constructors of the column.
7170 fn analyze_ctors ( & self , pcx : & PlaceCtxt < ' _ , ' p , ' tcx > ) -> SplitConstructorSet < ' p , ' tcx > {
7271 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)
7473 }
7574
7675 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> {
121120
122121/// Traverse the patterns to collect any variants of a non_exhaustive enum that fail to be mentioned
123122/// in a given column.
124- #[ instrument( level = "debug" , skip( cx, wildcard_arena ) , ret) ]
123+ #[ instrument( level = "debug" , skip( cx) , ret) ]
125124fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
126- cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
125+ cx : MatchCtxt < ' a , ' p , ' tcx > ,
127126 column : & PatternColumn < ' a , ' p , ' tcx > ,
128- wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
129127) -> Vec < WitnessPat < ' p , ' tcx > > {
130128 let Some ( ty) = column. head_ty ( ) else {
131129 return Vec :: new ( ) ;
132130 } ;
133- let pcx = & PlaceCtxt :: new_dummy ( cx, ty, wildcard_arena ) ;
131+ let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
134132
135133 let set = column. analyze_ctors ( pcx) ;
136134 if set. present . is_empty ( ) {
@@ -141,7 +139,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
141139 }
142140
143141 let mut witnesses = Vec :: new ( ) ;
144- if cx. is_foreign_non_exhaustive_enum ( ty) {
142+ if cx. tycx . is_foreign_non_exhaustive_enum ( ty) {
145143 witnesses. extend (
146144 set. missing
147145 . into_iter ( )
@@ -157,7 +155,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
157155 let wild_pat = WitnessPat :: wild_from_ctor ( pcx, ctor) ;
158156 for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
159157 // 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) ;
161159 // For each witness, we build a new pattern in the shape of `ctor(_, _, wit, _, _)`,
162160 // adding enough wildcards to match `arity`.
163161 for wit in wits_for_col_i {
@@ -171,29 +169,29 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
171169}
172170
173171pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
174- cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
172+ cx : MatchCtxt < ' a , ' p , ' tcx > ,
175173 arms : & [ MatchArm < ' p , ' tcx > ] ,
176174 pat_column : & PatternColumn < ' a , ' p , ' tcx > ,
177175 scrut_ty : Ty < ' tcx > ,
178- wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
179176) {
177+ let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
180178 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 ,
182180 rustc_session:: lint:: Level :: Allow
183181 ) {
184- let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column, wildcard_arena ) ;
182+ let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ;
185183 if !witnesses. is_empty ( ) {
186184 // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
187185 // is not exhaustive enough.
188186 //
189187 // 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 (
191189 NON_EXHAUSTIVE_OMITTED_PATTERNS ,
192- cx . match_lint_level ,
193- cx . scrut_span ,
190+ rcx . match_lint_level ,
191+ rcx . scrut_span ,
194192 NonExhaustiveOmittedPattern {
195193 scrut_ty,
196- uncovered : Uncovered :: new ( cx . scrut_span , cx , witnesses) ,
194+ uncovered : Uncovered :: new ( rcx . scrut_span , rcx , witnesses) ,
197195 } ,
198196 ) ;
199197 }
@@ -203,17 +201,17 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
203201 // usage of the lint.
204202 for arm in arms {
205203 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 ) ;
207205 if !matches ! ( lint_level, rustc_session:: lint:: Level :: Allow ) {
208206 let decorator = NonExhaustiveOmittedPatternLintOnArm {
209207 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 ( ) ) ,
211209 lint_level : lint_level. as_str ( ) ,
212210 lint_name : "non_exhaustive_omitted_patterns" ,
213211 } ;
214212
215213 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 ( ) , "" ) ;
217215 err. set_primary_message ( decorator. msg ( ) ) ;
218216 decorator. decorate_lint ( & mut err) ;
219217 err. emit ( ) ;
@@ -223,30 +221,30 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
223221}
224222
225223/// 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) ) ]
227225pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
228- cx : & RustcMatchCheckCtxt < ' p , ' tcx > ,
226+ cx : MatchCtxt < ' a , ' p , ' tcx > ,
229227 column : & PatternColumn < ' a , ' p , ' tcx > ,
230- wildcard_arena : & TypedArena < DeconstructedPat < ' p , ' tcx > > ,
231228) {
232229 let Some ( ty) = column. head_ty ( ) else {
233230 return ;
234231 } ;
235- let pcx = & PlaceCtxt :: new_dummy ( cx, ty, wildcard_arena) ;
232+ let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
233+ let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
236234
237235 let set = column. analyze_ctors ( pcx) ;
238236
239237 if matches ! ( ty. kind( ) , ty:: Char | ty:: Int ( _) | ty:: Uint ( _) ) {
240238 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) ;
242240 let overlaps: Vec < _ > = overlapped_spans
243241 . iter ( )
244242 . copied ( )
245243 . map ( |span| Overlap { range : overlap_as_pat. clone ( ) , span } )
246244 . collect ( ) ;
247- cx . tcx . emit_spanned_lint (
245+ rcx . tcx . emit_spanned_lint (
248246 lint:: builtin:: OVERLAPPING_RANGE_ENDPOINTS ,
249- cx . match_lint_level ,
247+ rcx . match_lint_level ,
250248 this_span,
251249 OverlappingRangeEndpoints { overlap : overlaps, range : this_span } ,
252250 ) ;
@@ -291,7 +289,7 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
291289 // Recurse into the fields.
292290 for ctor in set. present {
293291 for col in column. specialize ( pcx, & ctor) {
294- lint_overlapping_range_endpoints ( cx, & col, wildcard_arena ) ;
292+ lint_overlapping_range_endpoints ( cx, & col) ;
295293 }
296294 }
297295 }
0 commit comments