Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2bf6e78

Browse files
committed
Remove some unreachable code
1 parent 2e78c6b commit 2bf6e78

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
190190
let scrut_ty = self.typeck_results.expr_ty_adjusted(scrut);
191191
let report = compute_match_usefulness(&cx, &arms, scrut.hir_id, scrut_ty);
192192

193-
report_arm_reachability(&cx, &report, |_, arm_span, arm_hir_id, catchall| {
193+
report_arm_reachability(&cx, &report, |arm_span, arm_hir_id, catchall| {
194194
match source {
195195
hir::MatchSource::ForLoopDesugar | hir::MatchSource::Normal => {
196196
unreachable_pattern(cx.tcx, arm_span, arm_hir_id, catchall);
@@ -434,23 +434,14 @@ fn check_let_reachability<'p, 'tcx>(
434434
let arms = [MatchArm { pat, hir_id: pat_id, has_guard: false }];
435435
let report = compute_match_usefulness(&cx, &arms, pat_id, pat.ty);
436436

437-
report_arm_reachability(&cx, &report, |arm_index, arm_span, arm_hir_id, _| {
438-
match let_source(cx.tcx, pat_id) {
439-
LetSource::IfLet | LetSource::WhileLet => {
440-
match arm_index {
441-
// The arm with the user-specified pattern.
442-
0 => unreachable_pattern(cx.tcx, arm_span, arm_hir_id, None),
443-
// The arm with the wildcard pattern.
444-
1 => irrefutable_let_pattern(cx.tcx, pat_id, arm_span),
445-
_ => bug!(),
446-
}
447-
}
448-
LetSource::IfLetGuard if arm_index == 0 => {
449-
unreachable_pattern(cx.tcx, arm_span, arm_hir_id, None);
450-
}
451-
_ => {}
437+
match let_source(cx.tcx, pat_id) {
438+
LetSource::IfLet | LetSource::WhileLet | LetSource::IfLetGuard => {
439+
report_arm_reachability(&cx, &report, |arm_span, arm_hir_id, _| {
440+
unreachable_pattern(cx.tcx, arm_span, arm_hir_id, None)
441+
});
452442
}
453-
});
443+
_ => {}
444+
}
454445

455446
if report.non_exhaustiveness_witnesses.is_empty() {
456447
// The match is exhaustive, i.e. the `if let` pattern is irrefutable.
@@ -464,13 +455,13 @@ fn report_arm_reachability<'p, 'tcx, F>(
464455
report: &UsefulnessReport<'p, 'tcx>,
465456
unreachable: F,
466457
) where
467-
F: Fn(usize, Span, HirId, Option<Span>),
458+
F: Fn(Span, HirId, Option<Span>),
468459
{
469460
use Reachability::*;
470461
let mut catchall = None;
471-
for (arm_index, (arm, is_useful)) in report.arm_usefulness.iter().enumerate() {
462+
for (arm, is_useful) in report.arm_usefulness.iter() {
472463
match is_useful {
473-
Unreachable => unreachable(arm_index, arm.pat.span, arm.hir_id, catchall),
464+
Unreachable => unreachable(arm.pat.span, arm.hir_id, catchall),
474465
Reachable(unreachables) if unreachables.is_empty() => {}
475466
// The arm is reachable, but contains unreachable subpatterns (from or-patterns).
476467
Reachable(unreachables) => {

0 commit comments

Comments
 (0)