@@ -19,7 +19,7 @@ use rustc_hir::HirId;
1919use rustc_middle:: thir:: visit:: { self , Visitor } ;
2020use rustc_middle:: thir:: * ;
2121use 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 } ;
2323use rustc_session:: lint:: builtin:: {
2424 BINDINGS_WITH_VARIANT_NAME , IRREFUTABLE_LET_PATTERNS , UNREACHABLE_PATTERNS ,
2525} ;
@@ -231,6 +231,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
231231 if let LetSource :: None = source {
232232 return ;
233233 }
234+ if let Err ( err) = pat. pat_error_reported ( ) {
235+ self . error = Err ( err) ;
236+ return ;
237+ }
234238 self . check_patterns ( pat, Refutable ) ;
235239 let mut cx = self . new_cx ( self . lint_level , true ) ;
236240 let tpat = self . lower_pattern ( & mut cx, pat) ;
@@ -252,6 +256,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
252256 self . with_lint_level ( arm. lint_level , |this| {
253257 this. check_patterns ( & arm. pattern , Refutable ) ;
254258 } ) ;
259+ if let Err ( err) = arm. pattern . pat_error_reported ( ) {
260+ self . error = Err ( err) ;
261+ return ;
262+ }
255263 }
256264
257265 let tarms: Vec < _ > = arms
@@ -334,7 +342,8 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
334342 // and record chain members that aren't let exprs.
335343 let mut chain_refutabilities = Vec :: new ( ) ;
336344
337- let add = |expr : ExprId , mut local_lint_level| {
345+ let mut error = Ok ( ( ) ) ;
346+ let mut add = |expr : ExprId , mut local_lint_level| {
338347 // `local_lint_level` is the lint level enclosing the pattern inside `expr`.
339348 let mut expr = & self . thir [ expr] ;
340349 debug ! ( ?expr, ?local_lint_level, "add" ) ;
@@ -348,6 +357,10 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
348357 debug ! ( ?expr, ?local_lint_level, "after scopes" ) ;
349358 match expr. kind {
350359 ExprKind :: Let { box ref pat, expr : _ } => {
360+ if let Err ( err) = pat. pat_error_reported ( ) {
361+ error = Err ( err) ;
362+ return None ;
363+ }
351364 let mut ncx = self . new_cx ( local_lint_level, true ) ;
352365 let tpat = self . lower_pattern ( & mut ncx, pat) ;
353366 let refutable = !is_let_irrefutable ( & mut ncx, local_lint_level, tpat) ;
@@ -380,6 +393,11 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
380393 debug ! ( ?chain_refutabilities) ;
381394 chain_refutabilities. reverse ( ) ;
382395
396+ if error. is_err ( ) {
397+ self . error = error;
398+ return ;
399+ }
400+
383401 // Third, emit the actual warnings.
384402 if chain_refutabilities. iter ( ) . all ( |r| matches ! ( * r, Some ( ( _, false ) ) ) ) {
385403 // The entire chain is made up of irrefutable `let` statements
@@ -426,6 +444,12 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
426444
427445 #[ instrument( level = "trace" , skip( self ) ) ]
428446 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+
429453 let mut cx = self . new_cx ( self . lint_level , false ) ;
430454
431455 let pattern = self . lower_pattern ( & mut cx, pat) ;
@@ -682,12 +706,6 @@ fn non_exhaustive_match<'p, 'tcx>(
682706 arms : & [ ArmId ] ,
683707 expr_span : Span ,
684708) -> ErrorGuaranteed {
685- for & arm in arms {
686- if let Err ( err) = thir[ arm] . pattern . error_reported ( ) {
687- return err;
688- }
689- }
690-
691709 let is_empty_match = arms. is_empty ( ) ;
692710 let non_empty_enum = match scrut_ty. kind ( ) {
693711 ty:: Adt ( def, _) => def. is_enum ( ) && !def. variants ( ) . is_empty ( ) ,
0 commit comments