@@ -19,7 +19,7 @@ use rustc_hir::HirId;
19
19
use rustc_middle:: thir:: visit:: { self , Visitor } ;
20
20
use rustc_middle:: thir:: * ;
21
21
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
22
- use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt , TypeVisitableExt } ;
22
+ use rustc_middle:: ty:: { self , AdtDef , Ty , TyCtxt } ;
23
23
use rustc_session:: lint:: builtin:: {
24
24
BINDINGS_WITH_VARIANT_NAME , IRREFUTABLE_LET_PATTERNS , UNREACHABLE_PATTERNS ,
25
25
} ;
@@ -231,6 +231,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
231
231
if let LetSource :: None = source {
232
232
return ;
233
233
}
234
+ if let Err ( err) = pat. pat_error_reported ( ) {
235
+ self . error = Err ( err) ;
236
+ return ;
237
+ }
234
238
self . check_patterns ( pat, Refutable ) ;
235
239
let mut cx = self . new_cx ( self . lint_level , true ) ;
236
240
let tpat = self . lower_pattern ( & mut cx, pat) ;
@@ -252,6 +256,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
252
256
self . with_lint_level ( arm. lint_level , |this| {
253
257
this. check_patterns ( & arm. pattern , Refutable ) ;
254
258
} ) ;
259
+ if let Err ( err) = arm. pattern . pat_error_reported ( ) {
260
+ self . error = Err ( err) ;
261
+ return ;
262
+ }
255
263
}
256
264
257
265
let tarms: Vec < _ > = arms
@@ -334,7 +342,8 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
334
342
// and record chain members that aren't let exprs.
335
343
let mut chain_refutabilities = Vec :: new ( ) ;
336
344
337
- let add = |expr : ExprId , mut local_lint_level| {
345
+ let mut error = Ok ( ( ) ) ;
346
+ let mut add = |expr : ExprId , mut local_lint_level| {
338
347
// `local_lint_level` is the lint level enclosing the pattern inside `expr`.
339
348
let mut expr = & self . thir [ expr] ;
340
349
debug ! ( ?expr, ?local_lint_level, "add" ) ;
@@ -348,6 +357,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
348
357
debug ! ( ?expr, ?local_lint_level, "after scopes" ) ;
349
358
match expr. kind {
350
359
ExprKind :: Let { box ref pat, expr : _ } => {
360
+ if let Err ( err) = pat. pat_error_reported ( ) {
361
+ error = Err ( err) ;
362
+ return None ;
363
+ }
351
364
let mut ncx = self . new_cx ( local_lint_level, true ) ;
352
365
let tpat = self . lower_pattern ( & mut ncx, pat) ;
353
366
let refutable = !is_let_irrefutable ( & mut ncx, local_lint_level, tpat) ;
@@ -380,6 +393,11 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
380
393
debug ! ( ?chain_refutabilities) ;
381
394
chain_refutabilities. reverse ( ) ;
382
395
396
+ if error. is_err ( ) {
397
+ self . error = error;
398
+ return ;
399
+ }
400
+
383
401
// Third, emit the actual warnings.
384
402
if chain_refutabilities. iter ( ) . all ( |r| matches ! ( * r, Some ( ( _, false ) ) ) ) {
385
403
// The entire chain is made up of irrefutable `let` statements
@@ -426,6 +444,12 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
426
444
427
445
#[ instrument( level = "trace" , skip( self ) ) ]
428
446
fn check_irrefutable ( & mut self , pat : & Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
447
+ // If we got errors while lowering, don't emit anything more.
448
+ if let Err ( err) = pat. pat_error_reported ( ) {
449
+ self . error = Err ( err) ;
450
+ return ;
451
+ }
452
+
429
453
let mut cx = self . new_cx ( self . lint_level , false ) ;
430
454
431
455
let pattern = self . lower_pattern ( & mut cx, pat) ;
@@ -682,12 +706,6 @@ fn non_exhaustive_match<'p, 'tcx>(
682
706
arms : & [ ArmId ] ,
683
707
expr_span : Span ,
684
708
) -> ErrorGuaranteed {
685
- for & arm in arms {
686
- if let Err ( err) = thir[ arm] . pattern . error_reported ( ) {
687
- return err;
688
- }
689
- }
690
-
691
709
let is_empty_match = arms. is_empty ( ) ;
692
710
let non_empty_enum = match scrut_ty. kind ( ) {
693
711
ty:: Adt ( def, _) => def. is_enum ( ) && !def. variants ( ) . is_empty ( ) ,
0 commit comments