Skip to content

Commit 36ecbc9

Browse files
committed
Auto merge of #80632 - Nadrieril:fix-80501, r=varkor
Identify unreachable subpatterns more reliably In #80104 I used `Span`s to identify unreachable sub-patterns in the presence of or-patterns during exhaustiveness checking. In #80501 it was revealed that `Span`s are complicated and that this was not a good idea. Instead, this PR identifies subpatterns logically: as a path in the tree of subpatterns of a given pattern. I made a struct that captures a set of such subpatterns. This is a bit complex, but thankfully self-contained; the rest of the code does not need to know anything about it. Fixes #80501. I think I managed to keep the perf neutral. r? `@varkor`
2 parents 5a5f3a9 + ae6fcab commit 36ecbc9

File tree

6 files changed

+472
-223
lines changed

6 files changed

+472
-223
lines changed

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::usefulness::Usefulness::*;
21
use super::usefulness::{
3-
compute_match_usefulness, expand_pattern, MatchArm, MatchCheckCtxt, UsefulnessReport,
2+
compute_match_usefulness, expand_pattern, MatchArm, MatchCheckCtxt, Reachability,
3+
UsefulnessReport,
44
};
55
use super::{PatCtxt, PatKind, PatternError};
66

@@ -398,10 +398,11 @@ fn report_arm_reachability<'p, 'tcx>(
398398
report: &UsefulnessReport<'p, 'tcx>,
399399
source: hir::MatchSource,
400400
) {
401+
use Reachability::*;
401402
let mut catchall = None;
402403
for (arm_index, (arm, is_useful)) in report.arm_usefulness.iter().enumerate() {
403404
match is_useful {
404-
NotUseful => {
405+
Unreachable => {
405406
match source {
406407
hir::MatchSource::WhileDesugar => bug!(),
407408

@@ -430,17 +431,16 @@ fn report_arm_reachability<'p, 'tcx>(
430431
hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar => {}
431432
}
432433
}
433-
Useful(unreachables) if unreachables.is_empty() => {}
434+
Reachable(unreachables) if unreachables.is_empty() => {}
434435
// The arm is reachable, but contains unreachable subpatterns (from or-patterns).
435-
Useful(unreachables) => {
436-
let mut unreachables: Vec<_> = unreachables.iter().collect();
436+
Reachable(unreachables) => {
437+
let mut unreachables = unreachables.clone();
437438
// Emit lints in the order in which they occur in the file.
438439
unreachables.sort_unstable();
439440
for span in unreachables {
440441
unreachable_pattern(cx.tcx, span, arm.hir_id, None);
441442
}
442443
}
443-
UsefulWithWitness(_) => bug!(),
444444
}
445445
if !arm.has_guard && catchall.is_none() && pat_is_catchall(arm.pat) {
446446
catchall = Some(arm.pat.span);

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

-2
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,6 @@ impl<'tcx> Constructor<'tcx> {
723723
where
724724
'tcx: 'a,
725725
{
726-
debug!("Constructor::split({:#?})", self);
727-
728726
match self {
729727
Wildcard => {
730728
let mut split_wildcard = SplitWildcard::new(pcx);

0 commit comments

Comments
 (0)