@@ -4,7 +4,7 @@ use rustc_data_structures::captures::Captures;
44use rustc_middle:: ty;
55use rustc_session:: lint;
66use rustc_session:: lint:: builtin:: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
7- use rustc_span:: Span ;
7+ use rustc_span:: { ErrorGuaranteed , Span } ;
88
99use crate :: constructor:: { IntRange , MaybeInfiniteInt } ;
1010use crate :: errors:: {
@@ -52,9 +52,13 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
5252 }
5353
5454 /// Do constructor splitting on the constructors of the column.
55- fn analyze_ctors ( & self , pcx : & PlaceCtxt < ' _ , ' p , ' tcx > ) -> SplitConstructorSet < ' p , ' tcx > {
55+ fn analyze_ctors (
56+ & self ,
57+ pcx : & PlaceCtxt < ' _ , ' p , ' tcx > ,
58+ ) -> Result < SplitConstructorSet < ' p , ' tcx > , ErrorGuaranteed > {
5659 let column_ctors = self . patterns . iter ( ) . map ( |p| p. ctor ( ) ) ;
57- pcx. ctors_for_ty ( ) . split ( pcx, column_ctors)
60+ let ctors_for_ty = & pcx. ctors_for_ty ( ) ?;
61+ Ok ( ctors_for_ty. split ( pcx, column_ctors) )
5862 }
5963
6064 fn iter ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , ' tcx > > + Captures < ' _ > {
@@ -110,18 +114,18 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
110114fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
111115 cx : MatchCtxt < ' a , ' p , ' tcx > ,
112116 column : & PatternColumn < ' p , ' tcx > ,
113- ) -> Vec < WitnessPat < ' p , ' tcx > > {
117+ ) -> Result < Vec < WitnessPat < ' p , ' tcx > > , ErrorGuaranteed > {
114118 let Some ( ty) = column. head_ty ( ) else {
115- return Vec :: new ( ) ;
119+ return Ok ( Vec :: new ( ) ) ;
116120 } ;
117121 let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
118122
119- let set = column. analyze_ctors ( pcx) ;
123+ let set = column. analyze_ctors ( pcx) ? ;
120124 if set. present . is_empty ( ) {
121125 // We can't consistently handle the case where no constructors are present (since this would
122126 // require digging deep through any type in case there's a non_exhaustive enum somewhere),
123127 // so for consistency we refuse to handle the top-level case, where we could handle it.
124- return vec ! [ ] ;
128+ return Ok ( Vec :: new ( ) ) ;
125129 }
126130
127131 let mut witnesses = Vec :: new ( ) ;
@@ -141,7 +145,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
141145 let wild_pat = WitnessPat :: wild_from_ctor ( pcx, ctor) ;
142146 for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
143147 // Compute witnesses for each column.
144- let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ;
148+ let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ? ;
145149 // For each witness, we build a new pattern in the shape of `ctor(_, _, wit, _, _)`,
146150 // adding enough wildcards to match `arity`.
147151 for wit in wits_for_col_i {
@@ -151,21 +155,21 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
151155 }
152156 }
153157 }
154- witnesses
158+ Ok ( witnesses)
155159}
156160
157161pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
158162 cx : MatchCtxt < ' a , ' p , ' tcx > ,
159163 arms : & [ MatchArm < ' p , ' tcx > ] ,
160164 pat_column : & PatternColumn < ' p , ' tcx > ,
161165 scrut_ty : RevealedTy < ' tcx > ,
162- ) {
166+ ) -> Result < ( ) , ErrorGuaranteed > {
163167 let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
164168 if !matches ! (
165169 rcx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , rcx. match_lint_level) . 0 ,
166170 rustc_session:: lint:: Level :: Allow
167171 ) {
168- let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ;
172+ let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ? ;
169173 if !witnesses. is_empty ( ) {
170174 // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
171175 // is not exhaustive enough.
@@ -204,21 +208,22 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
204208 }
205209 }
206210 }
211+ Ok ( ( ) )
207212}
208213
209214/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
210215#[ instrument( level = "debug" , skip( cx) ) ]
211216pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
212217 cx : MatchCtxt < ' a , ' p , ' tcx > ,
213218 column : & PatternColumn < ' p , ' tcx > ,
214- ) {
219+ ) -> Result < ( ) , ErrorGuaranteed > {
215220 let Some ( ty) = column. head_ty ( ) else {
216- return ;
221+ return Ok ( ( ) ) ;
217222 } ;
218223 let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
219224 let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
220225
221- let set = column. analyze_ctors ( pcx) ;
226+ let set = column. analyze_ctors ( pcx) ? ;
222227
223228 if matches ! ( ty. kind( ) , ty:: Char | ty:: Int ( _) | ty:: Uint ( _) ) {
224229 let emit_lint = |overlap : & IntRange , this_span : Span , overlapped_spans : & [ Span ] | {
@@ -275,8 +280,9 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
275280 // Recurse into the fields.
276281 for ctor in set. present {
277282 for col in column. specialize ( pcx, & ctor) {
278- lint_overlapping_range_endpoints ( cx, & col) ;
283+ lint_overlapping_range_endpoints ( cx, & col) ? ;
279284 }
280285 }
281286 }
287+ Ok ( ( ) )
282288}
0 commit comments