@@ -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:: {
@@ -110,9 +110,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
110110fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
111111 cx : MatchCtxt < ' a , ' p , ' tcx > ,
112112 column : & PatternColumn < ' p , ' tcx > ,
113- ) -> Vec < WitnessPat < ' p , ' tcx > > {
113+ ) -> Result < Vec < WitnessPat < ' p , ' tcx > > , ErrorGuaranteed > {
114114 let Some ( ty) = column. head_ty ( ) else {
115- return Vec :: new ( ) ;
115+ return Ok ( Vec :: new ( ) ) ;
116116 } ;
117117 let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
118118
@@ -121,7 +121,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
121121 // We can't consistently handle the case where no constructors are present (since this would
122122 // require digging deep through any type in case there's a non_exhaustive enum somewhere),
123123 // so for consistency we refuse to handle the top-level case, where we could handle it.
124- return vec ! [ ] ;
124+ return Ok ( Vec :: new ( ) ) ;
125125 }
126126
127127 let mut witnesses = Vec :: new ( ) ;
@@ -141,7 +141,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
141141 let wild_pat = WitnessPat :: wild_from_ctor ( pcx, ctor) ;
142142 for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
143143 // Compute witnesses for each column.
144- let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ;
144+ let wits_for_col_i = collect_nonexhaustive_missing_variants ( cx, col_i) ? ;
145145 // For each witness, we build a new pattern in the shape of `ctor(_, _, wit, _, _)`,
146146 // adding enough wildcards to match `arity`.
147147 for wit in wits_for_col_i {
@@ -151,21 +151,21 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
151151 }
152152 }
153153 }
154- witnesses
154+ Ok ( witnesses)
155155}
156156
157157pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
158158 cx : MatchCtxt < ' a , ' p , ' tcx > ,
159159 arms : & [ MatchArm < ' p , ' tcx > ] ,
160160 pat_column : & PatternColumn < ' p , ' tcx > ,
161161 scrut_ty : RevealedTy < ' tcx > ,
162- ) {
162+ ) -> Result < ( ) , ErrorGuaranteed > {
163163 let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
164164 if !matches ! (
165165 rcx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , rcx. match_lint_level) . 0 ,
166166 rustc_session:: lint:: Level :: Allow
167167 ) {
168- let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ;
168+ let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ? ;
169169 if !witnesses. is_empty ( ) {
170170 // Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
171171 // is not exhaustive enough.
@@ -204,16 +204,17 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
204204 }
205205 }
206206 }
207+ Ok ( ( ) )
207208}
208209
209210/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
210211#[ instrument( level = "debug" , skip( cx) ) ]
211212pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
212213 cx : MatchCtxt < ' a , ' p , ' tcx > ,
213214 column : & PatternColumn < ' p , ' tcx > ,
214- ) {
215+ ) -> Result < ( ) , ErrorGuaranteed > {
215216 let Some ( ty) = column. head_ty ( ) else {
216- return ;
217+ return Ok ( ( ) ) ;
217218 } ;
218219 let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
219220 let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
@@ -275,8 +276,9 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
275276 // Recurse into the fields.
276277 for ctor in set. present {
277278 for col in column. specialize ( pcx, & ctor) {
278- lint_overlapping_range_endpoints ( cx, & col) ;
279+ lint_overlapping_range_endpoints ( cx, & col) ? ;
279280 }
280281 }
281282 }
283+ Ok ( ( ) )
282284}
0 commit comments