Skip to content

Commit 5547105

Browse files
committed
Don't expose Usefulness in the api
1 parent 3a4c135 commit 5547105

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

Lines changed: 6 additions & 6 deletions
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+
Reachable(unreachables) => {
436437
let mut unreachables: Vec<_> = unreachables.iter().collect();
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/usefulness.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl SpanSet {
679679
}
680680

681681
#[derive(Clone, Debug)]
682-
crate enum Usefulness<'tcx> {
682+
enum Usefulness<'tcx> {
683683
/// Pontentially carries a set of sub-branches that have been found to be unreachable. Used
684684
/// only in the presence of or-patterns, otherwise it stays empty.
685685
Useful(SpanSet),
@@ -1024,10 +1024,18 @@ crate struct MatchArm<'p, 'tcx> {
10241024
crate has_guard: bool,
10251025
}
10261026

1027+
#[derive(Clone, Debug)]
1028+
crate enum Reachability {
1029+
/// Potentially carries a set of sub-branches that have been found to be unreachable. Used only
1030+
/// in the presence of or-patterns, otherwise it stays empty.
1031+
Reachable(SpanSet),
1032+
Unreachable,
1033+
}
1034+
10271035
/// The output of checking a match for exhaustiveness and arm reachability.
10281036
crate struct UsefulnessReport<'p, 'tcx> {
10291037
/// For each arm of the input, whether that arm is reachable after the arms above it.
1030-
crate arm_usefulness: Vec<(MatchArm<'p, 'tcx>, Usefulness<'tcx>)>,
1038+
crate arm_usefulness: Vec<(MatchArm<'p, 'tcx>, Reachability)>,
10311039
/// If the match is exhaustive, this is empty. If not, this contains witnesses for the lack of
10321040
/// exhaustiveness.
10331041
crate non_exhaustiveness_witnesses: Vec<super::Pat<'tcx>>,
@@ -1055,7 +1063,12 @@ crate fn compute_match_usefulness<'p, 'tcx>(
10551063
if !arm.has_guard {
10561064
matrix.push(v);
10571065
}
1058-
(arm, usefulness)
1066+
let reachability = match usefulness {
1067+
Useful(spans) => Reachability::Reachable(spans),
1068+
NotUseful => Reachability::Unreachable,
1069+
UsefulWithWitness(..) => bug!(),
1070+
};
1071+
(arm, reachability)
10591072
})
10601073
.collect();
10611074

0 commit comments

Comments
 (0)