diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2021-09-13 15:44:30 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2021-09-26 00:05:52 +0100 |
| commit | 2bf6e7880ddab107219ec493952dc8d74c749a5b (patch) | |
| tree | e7f69a7a9201d1c1e0038223228d9836bcc0f137 | |
| parent | 2e78c6bd993d84bd975a5f2f1d68dc7e75c5435e (diff) | |
| download | rust-2bf6e7880ddab107219ec493952dc8d74c749a5b.tar.gz rust-2bf6e7880ddab107219ec493952dc8d74c749a5b.zip | |
Remove some unreachable code
| -rw-r--r-- | compiler/rustc_mir_build/src/thir/pattern/check_match.rs | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 4c51b9207bb..724ac545315 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -190,7 +190,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { let scrut_ty = self.typeck_results.expr_ty_adjusted(scrut); let report = compute_match_usefulness(&cx, &arms, scrut.hir_id, scrut_ty); - report_arm_reachability(&cx, &report, |_, arm_span, arm_hir_id, catchall| { + report_arm_reachability(&cx, &report, |arm_span, arm_hir_id, catchall| { match source { hir::MatchSource::ForLoopDesugar | hir::MatchSource::Normal => { unreachable_pattern(cx.tcx, arm_span, arm_hir_id, catchall); @@ -434,23 +434,14 @@ fn check_let_reachability<'p, 'tcx>( let arms = [MatchArm { pat, hir_id: pat_id, has_guard: false }]; let report = compute_match_usefulness(&cx, &arms, pat_id, pat.ty); - report_arm_reachability(&cx, &report, |arm_index, arm_span, arm_hir_id, _| { - match let_source(cx.tcx, pat_id) { - LetSource::IfLet | LetSource::WhileLet => { - match arm_index { - // The arm with the user-specified pattern. - 0 => unreachable_pattern(cx.tcx, arm_span, arm_hir_id, None), - // The arm with the wildcard pattern. - 1 => irrefutable_let_pattern(cx.tcx, pat_id, arm_span), - _ => bug!(), - } - } - LetSource::IfLetGuard if arm_index == 0 => { - unreachable_pattern(cx.tcx, arm_span, arm_hir_id, None); - } - _ => {} + match let_source(cx.tcx, pat_id) { + LetSource::IfLet | LetSource::WhileLet | LetSource::IfLetGuard => { + report_arm_reachability(&cx, &report, |arm_span, arm_hir_id, _| { + unreachable_pattern(cx.tcx, arm_span, arm_hir_id, None) + }); } - }); + _ => {} + } if report.non_exhaustiveness_witnesses.is_empty() { // The match is exhaustive, i.e. the `if let` pattern is irrefutable. @@ -464,13 +455,13 @@ fn report_arm_reachability<'p, 'tcx, F>( report: &UsefulnessReport<'p, 'tcx>, unreachable: F, ) where - F: Fn(usize, Span, HirId, Option<Span>), + F: Fn(Span, HirId, Option<Span>), { use Reachability::*; let mut catchall = None; - for (arm_index, (arm, is_useful)) in report.arm_usefulness.iter().enumerate() { + for (arm, is_useful) in report.arm_usefulness.iter() { match is_useful { - Unreachable => unreachable(arm_index, arm.pat.span, arm.hir_id, catchall), + Unreachable => unreachable(arm.pat.span, arm.hir_id, catchall), Reachable(unreachables) if unreachables.is_empty() => {} // The arm is reachable, but contains unreachable subpatterns (from or-patterns). Reachable(unreachables) => { |
