@@ -4,7 +4,7 @@ use rustc_data_structures::captures::Captures;
4
4
use rustc_middle:: ty;
5
5
use rustc_session:: lint;
6
6
use rustc_session:: lint:: builtin:: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
7
- use rustc_span:: Span ;
7
+ use rustc_span:: { ErrorGuaranteed , Span } ;
8
8
9
9
use crate :: constructor:: { IntRange , MaybeInfiniteInt } ;
10
10
use crate :: errors:: {
@@ -110,9 +110,9 @@ impl<'p, 'tcx> PatternColumn<'p, 'tcx> {
110
110
fn collect_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
111
111
cx : MatchCtxt < ' a , ' p , ' tcx > ,
112
112
column : & PatternColumn < ' p , ' tcx > ,
113
- ) -> Vec < WitnessPat < ' p , ' tcx > > {
113
+ ) -> Result < Vec < WitnessPat < ' p , ' tcx > > , ErrorGuaranteed > {
114
114
let Some ( ty) = column. head_ty ( ) else {
115
- return Vec :: new ( ) ;
115
+ return Ok ( Vec :: new ( ) ) ;
116
116
} ;
117
117
let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
118
118
@@ -121,7 +121,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
121
121
// We can't consistently handle the case where no constructors are present (since this would
122
122
// require digging deep through any type in case there's a non_exhaustive enum somewhere),
123
123
// so for consistency we refuse to handle the top-level case, where we could handle it.
124
- return vec ! [ ] ;
124
+ return Ok ( Vec :: new ( ) ) ;
125
125
}
126
126
127
127
let mut witnesses = Vec :: new ( ) ;
@@ -141,7 +141,7 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
141
141
let wild_pat = WitnessPat :: wild_from_ctor ( pcx, ctor) ;
142
142
for ( i, col_i) in specialized_columns. iter ( ) . enumerate ( ) {
143
143
// 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) ? ;
145
145
// For each witness, we build a new pattern in the shape of `ctor(_, _, wit, _, _)`,
146
146
// adding enough wildcards to match `arity`.
147
147
for wit in wits_for_col_i {
@@ -151,21 +151,21 @@ fn collect_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
151
151
}
152
152
}
153
153
}
154
- witnesses
154
+ Ok ( witnesses)
155
155
}
156
156
157
157
pub ( crate ) fn lint_nonexhaustive_missing_variants < ' a , ' p , ' tcx > (
158
158
cx : MatchCtxt < ' a , ' p , ' tcx > ,
159
159
arms : & [ MatchArm < ' p , ' tcx > ] ,
160
160
pat_column : & PatternColumn < ' p , ' tcx > ,
161
161
scrut_ty : RevealedTy < ' tcx > ,
162
- ) {
162
+ ) -> Result < ( ) , ErrorGuaranteed > {
163
163
let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
164
164
if !matches ! (
165
165
rcx. tcx. lint_level_at_node( NON_EXHAUSTIVE_OMITTED_PATTERNS , rcx. match_lint_level) . 0 ,
166
166
rustc_session:: lint:: Level :: Allow
167
167
) {
168
- let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ;
168
+ let witnesses = collect_nonexhaustive_missing_variants ( cx, pat_column) ? ;
169
169
if !witnesses. is_empty ( ) {
170
170
// Report that a match of a `non_exhaustive` enum marked with `non_exhaustive_omitted_patterns`
171
171
// is not exhaustive enough.
@@ -204,16 +204,17 @@ pub(crate) fn lint_nonexhaustive_missing_variants<'a, 'p, 'tcx>(
204
204
}
205
205
}
206
206
}
207
+ Ok ( ( ) )
207
208
}
208
209
209
210
/// Traverse the patterns to warn the user about ranges that overlap on their endpoints.
210
211
#[ instrument( level = "debug" , skip( cx) ) ]
211
212
pub ( crate ) fn lint_overlapping_range_endpoints < ' a , ' p , ' tcx > (
212
213
cx : MatchCtxt < ' a , ' p , ' tcx > ,
213
214
column : & PatternColumn < ' p , ' tcx > ,
214
- ) {
215
+ ) -> Result < ( ) , ErrorGuaranteed > {
215
216
let Some ( ty) = column. head_ty ( ) else {
216
- return ;
217
+ return Ok ( ( ) ) ;
217
218
} ;
218
219
let pcx = & PlaceCtxt :: new_dummy ( cx, ty) ;
219
220
let rcx: & RustcMatchCheckCtxt < ' _ , ' _ > = cx. tycx ;
@@ -275,8 +276,9 @@ pub(crate) fn lint_overlapping_range_endpoints<'a, 'p, 'tcx>(
275
276
// Recurse into the fields.
276
277
for ctor in set. present {
277
278
for col in column. specialize ( pcx, & ctor) {
278
- lint_overlapping_range_endpoints ( cx, & col) ;
279
+ lint_overlapping_range_endpoints ( cx, & col) ? ;
279
280
}
280
281
}
281
282
}
283
+ Ok ( ( ) )
282
284
}
0 commit comments