@@ -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
}
@@ -406,7 +410,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
406
410
}
407
411
408
412
#[ instrument( level = "trace" , skip( self ) ) ]
409
- fn check_irrefutable ( & self , pat : & Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
413
+ fn check_irrefutable ( & mut self , pat : & Pat < ' tcx > , origin : & str , sp : Option < Span > ) {
410
414
let mut cx = self . new_cx ( self . lint_level , false ) ;
411
415
412
416
let pattern = self . lower_pattern ( & mut cx, pat) ;
@@ -475,7 +479,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
475
479
AdtDefinedHere { adt_def_span, ty, variants }
476
480
} ;
477
481
478
- self . tcx . sess . emit_err ( PatternNotCovered {
482
+ self . error = Err ( self . tcx . sess . emit_err ( PatternNotCovered {
479
483
span : pat. span ,
480
484
origin,
481
485
uncovered : Uncovered :: new ( pat. span , & cx, witnesses) ,
@@ -486,7 +490,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
486
490
let_suggestion,
487
491
misc_suggestion,
488
492
adt_defined_here,
489
- } ) ;
493
+ } ) ) ;
490
494
}
491
495
}
492
496
@@ -628,7 +632,7 @@ fn non_exhaustive_match<'p, 'tcx>(
628
632
witnesses : Vec < DeconstructedPat < ' p , ' tcx > > ,
629
633
arms : & [ ArmId ] ,
630
634
expr_span : Span ,
631
- ) {
635
+ ) -> ErrorGuaranteed {
632
636
let is_empty_match = arms. is_empty ( ) ;
633
637
let non_empty_enum = match scrut_ty. kind ( ) {
634
638
ty:: Adt ( def, _) => def. is_enum ( ) && !def. variants ( ) . is_empty ( ) ,
@@ -640,13 +644,12 @@ fn non_exhaustive_match<'p, 'tcx>(
640
644
let pattern;
641
645
let patterns_len;
642
646
if is_empty_match && !non_empty_enum {
643
- cx. tcx . sess . emit_err ( NonExhaustivePatternsTypeNotEmpty {
647
+ return cx. tcx . sess . emit_err ( NonExhaustivePatternsTypeNotEmpty {
644
648
cx,
645
649
expr_span,
646
650
span : sp,
647
651
ty : scrut_ty,
648
652
} ) ;
649
- return ;
650
653
} else {
651
654
// FIXME: migration of this diagnostic will require list support
652
655
let joined_patterns = joined_uncovered_patterns ( cx, & witnesses) ;
@@ -797,7 +800,7 @@ fn non_exhaustive_match<'p, 'tcx>(
797
800
} else {
798
801
err. help ( msg) ;
799
802
}
800
- err. emit ( ) ;
803
+ err. emit ( )
801
804
}
802
805
803
806
pub ( crate ) fn joined_uncovered_patterns < ' p , ' tcx > (
0 commit comments