@@ -190,20 +190,16 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
190
190
let scrut_ty = self . typeck_results . expr_ty_adjusted ( scrut) ;
191
191
let report = compute_match_usefulness ( & cx, & arms, scrut. hir_id , scrut_ty) ;
192
192
193
- report_arm_reachability ( & cx, & report, |arm_span, arm_hir_id, catchall| {
194
- match source {
195
- hir:: MatchSource :: ForLoopDesugar | hir:: MatchSource :: Normal => {
196
- unreachable_pattern ( cx. tcx , arm_span, arm_hir_id, catchall) ;
197
- }
198
- // Unreachable patterns in try and await expressions occur when one of
199
- // the arms are an uninhabited type. Which is OK.
200
- hir:: MatchSource :: AwaitDesugar | hir:: MatchSource :: TryDesugar => { }
193
+ match source {
194
+ hir:: MatchSource :: ForLoopDesugar | hir:: MatchSource :: Normal => {
195
+ report_arm_reachability ( & cx, & report)
201
196
}
202
- } ) ;
197
+ // Unreachable patterns in try and await expressions occur when one of
198
+ // the arms are an uninhabited type. Which is OK.
199
+ hir:: MatchSource :: AwaitDesugar | hir:: MatchSource :: TryDesugar => { }
200
+ }
203
201
204
202
// Check if the match is exhaustive.
205
- // Note: An empty match isn't the same as an empty matrix for diagnostics purposes,
206
- // since an empty matrix can occur when there are arms, if those arms all have guards.
207
203
let is_empty_match = arms. is_empty ( ) ;
208
204
let witnesses = report. non_exhaustiveness_witnesses ;
209
205
if !witnesses. is_empty ( ) {
@@ -434,9 +430,10 @@ fn check_let_reachability<'p, 'tcx>(
434
430
let arms = [ MatchArm { pat, hir_id : pat_id, has_guard : false } ] ;
435
431
let report = compute_match_usefulness ( & cx, & arms, pat_id, pat. ty ) ;
436
432
437
- report_arm_reachability ( & cx, & report, |arm_span, arm_hir_id, _| {
438
- unreachable_pattern ( cx. tcx , arm_span, arm_hir_id, None )
439
- } ) ;
433
+ // Report if the pattern is unreachable, which can only occur when the type is uninhabited.
434
+ // This also reports unreachable sub-patterns though, so we can't just replace it with an
435
+ // `is_uninhabited` check.
436
+ report_arm_reachability ( & cx, & report) ;
440
437
441
438
if report. non_exhaustiveness_witnesses . is_empty ( ) {
442
439
// The match is exhaustive, i.e. the `if let` pattern is irrefutable.
@@ -445,18 +442,15 @@ fn check_let_reachability<'p, 'tcx>(
445
442
}
446
443
447
444
/// Report unreachable arms, if any.
448
- fn report_arm_reachability < ' p , ' tcx , F > (
445
+ fn report_arm_reachability < ' p , ' tcx > (
449
446
cx : & MatchCheckCtxt < ' p , ' tcx > ,
450
447
report : & UsefulnessReport < ' p , ' tcx > ,
451
- unreachable : F ,
452
- ) where
453
- F : Fn ( Span , HirId , Option < Span > ) ,
454
- {
448
+ ) {
455
449
use Reachability :: * ;
456
450
let mut catchall = None ;
457
451
for ( arm, is_useful) in report. arm_usefulness . iter ( ) {
458
452
match is_useful {
459
- Unreachable => unreachable ( arm. pat . span , arm. hir_id , catchall) ,
453
+ Unreachable => unreachable_pattern ( cx . tcx , arm. pat . span , arm. hir_id , catchall) ,
460
454
Reachable ( unreachables) if unreachables. is_empty ( ) => { }
461
455
// The arm is reachable, but contains unreachable subpatterns (from or-patterns).
462
456
Reachable ( unreachables) => {
0 commit comments