@@ -26,8 +26,8 @@ use rustc_session::Session;
26
26
use rustc_span:: hygiene:: DesugaringKind ;
27
27
use rustc_span:: Span ;
28
28
29
- pub ( crate ) fn check_match ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) {
30
- let Ok ( ( thir, expr) ) = tcx. thir_body ( def_id) else { return } ;
29
+ pub ( crate ) fn check_match ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Result < ( ) , ErrorGuaranteed > {
30
+ let ( thir, expr) = tcx. thir_body ( def_id) ? ;
31
31
let thir = thir. borrow ( ) ;
32
32
let pattern_arena = TypedArena :: default ( ) ;
33
33
let mut visitor = MatchVisitor {
@@ -37,13 +37,16 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) {
37
37
lint_level : tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ,
38
38
let_source : LetSource :: None ,
39
39
pattern_arena : & pattern_arena,
40
+ error : Ok ( ( ) ) ,
40
41
} ;
41
42
visitor. visit_expr ( & thir[ expr] ) ;
43
+
42
44
for param in thir. params . iter ( ) {
43
45
if let Some ( box ref pattern) = param. pat {
44
46
visitor. check_irrefutable ( pattern, "function argument" , None ) ;
45
47
}
46
48
}
49
+ visitor. error
47
50
}
48
51
49
52
fn create_e0004 (
@@ -77,6 +80,7 @@ struct MatchVisitor<'a, 'p, 'tcx> {
77
80
lint_level : HirId ,
78
81
let_source : LetSource ,
79
82
pattern_arena : & ' p TypedArena < DeconstructedPat < ' p , ' tcx > > ,
83
+ error : Result < ( ) , ErrorGuaranteed > ,
80
84
}
81
85
82
86
impl < ' a , ' tcx > Visitor < ' a , ' tcx > for MatchVisitor < ' a , ' _ , ' tcx > {
@@ -276,9 +280,9 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
276
280
let [ pat_field] = & subpatterns[ ..] else { bug ! ( ) } ;
277
281
self . check_irrefutable ( & pat_field. pattern , "`for` loop binding" , None ) ;
278
282
} else {
279
- non_exhaustive_match (
283
+ self . error = Err ( non_exhaustive_match (
280
284
& cx, self . thir , scrut_ty, scrut. span , witnesses, arms, expr_span,
281
- ) ;
285
+ ) ) ;
282
286
}
283
287
}
284
288
}
@@ -409,7 +413,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
409
413
}
410
414
411
415
#[ instrument( level = "trace" , skip( self ) ) ]
412
- fn check_irrefutable ( & self , pat : & Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
416
+ fn check_irrefutable ( & mut self , pat : & Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
413
417
let mut cx = self . new_cx ( self . lint_level , false ) ;
414
418
415
419
let pattern = self . lower_pattern ( & mut cx, pat) ;
@@ -478,7 +482,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
478
482
AdtDefinedHere { adt_def_span, ty, variants }
479
483
} ;
480
484
481
- self . tcx . sess . emit_err ( PatternNotCovered {
485
+ self . error = Err ( self . tcx . sess . emit_err ( PatternNotCovered {
482
486
span : pat. span ,
483
487
origin,
484
488
uncovered : Uncovered :: new ( pat. span , & cx, witnesses) ,
@@ -489,7 +493,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
489
493
let_suggestion,
490
494
misc_suggestion,
491
495
adt_defined_here,
492
- } ) ;
496
+ } ) ) ;
493
497
}
494
498
}
495
499
@@ -631,7 +635,7 @@ fn non_exhaustive_match<'p, 'tcx>(
631
635
witnesses : Vec < DeconstructedPat < ' p , ' tcx > > ,
632
636
arms : & [ ArmId ] ,
633
637
expr_span : Span ,
634
- ) {
638
+ ) -> ErrorGuaranteed {
635
639
let is_empty_match = arms. is_empty ( ) ;
636
640
let non_empty_enum = match scrut_ty. kind ( ) {
637
641
ty:: Adt ( def, _) => def. is_enum ( ) && !def. variants ( ) . is_empty ( ) ,
@@ -643,13 +647,12 @@ fn non_exhaustive_match<'p, 'tcx>(
643
647
let pattern;
644
648
let patterns_len;
645
649
if is_empty_match && !non_empty_enum {
646
- cx. tcx . sess . emit_err ( NonExhaustivePatternsTypeNotEmpty {
650
+ return cx. tcx . sess . emit_err ( NonExhaustivePatternsTypeNotEmpty {
647
651
cx,
648
652
expr_span,
649
653
span : sp,
650
654
ty : scrut_ty,
651
655
} ) ;
652
- return ;
653
656
} else {
654
657
// FIXME: migration of this diagnostic will require list support
655
658
let joined_patterns = joined_uncovered_patterns ( cx, & witnesses) ;
@@ -800,7 +803,7 @@ fn non_exhaustive_match<'p, 'tcx>(
800
803
} else {
801
804
err. help ( & msg) ;
802
805
}
803
- err. emit ( ) ;
806
+ err. emit ( )
804
807
}
805
808
806
809
pub ( crate ) fn joined_uncovered_patterns < ' p , ' tcx > (
0 commit comments