Skip to content

Commit 7925e12

Browse files
committed
tweak
1 parent 6630df5 commit 7925e12

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ impl IntRange {
261261
}
262262
}
263263
if !overlaps.is_empty() {
264-
let overlap_as_pat =
265-
(IntRange { range: overlap..=overlap }).to_pat(pcx.cx.tcx, pcx.ty);
264+
let overlap_as_pat = self.to_pat(pcx.cx.tcx, pcx.ty);
266265
let overlaps: Vec<_> = overlaps
267266
.into_iter()
268267
.map(|span| Overlap { range: overlap_as_pat.clone(), span })
@@ -995,24 +994,23 @@ impl ConstructorSet {
995994
}
996995
ConstructorSet::Variants { variants, non_exhaustive } => {
997996
let seen_set: FxHashSet<_> = seen.iter().map(|c| c.as_variant().unwrap()).collect();
998-
let mut skipped_any_missing_variant = false;
997+
let mut skipped_a_hidden_variant = false;
999998
for variant in variants {
1000999
let ctor = Variant(*variant);
10011000
if seen_set.contains(&variant) {
10021001
present.push(ctor);
10031002
} else if ctor.is_doc_hidden_variant(pcx) || ctor.is_unstable_variant(pcx) {
1004-
// We don't want to mention any variants that are `doc(hidden)` or
1005-
// behind an unstable feature gate.
1006-
skipped_any_missing_variant = true;
1003+
// We don't want to mention any variants that are `doc(hidden)` or behind an
1004+
// unstable feature gate if they aren't present in the match.
1005+
skipped_a_hidden_variant = true;
10071006
} else {
10081007
missing.push(ctor);
10091008
}
10101009
}
1011-
if skipped_any_missing_variant {
1012-
missing.push(Wildcard);
1013-
}
10141010
if *non_exhaustive {
10151011
missing.push(NonExhaustive);
1012+
} else if skipped_a_hidden_variant {
1013+
missing.push(Wildcard);
10161014
}
10171015
}
10181016
ConstructorSet::Integers { range_1, range_2, non_exhaustive } => {

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,6 @@ fn compute_usefulness<'p, 'tcx>(
804804
// For each constructor, we compute whether there's a value that starts with it that would
805805
// witness the usefulness of `v`.
806806
let mut ret = WitnessMatrix::new_empty();
807-
let orig_column_count = matrix.column_count();
808807
for ctor in split_ctors {
809808
debug!("specialize({:?})", ctor);
810809
let mut spec_matrix = matrix.specialize_constructor(pcx, &ctor);
@@ -814,12 +813,12 @@ fn compute_usefulness<'p, 'tcx>(
814813
ret.extend(witnesses);
815814

816815
// Lint on likely incorrect range patterns (#63987)
817-
if spec_matrix.rows().len() >= 2 {
816+
if spec_matrix.rows().len() >= 2 && matches!(ctor_set, ConstructorSet::Integers { .. }) {
818817
if let Constructor::IntRange(overlap_range) = &ctor {
819818
// If two ranges overlap on their boundaries, that boundary will be found as a singleton
820819
// range after splitting.
821820
// We limit to a single column for now, see `lint_overlapping_range_endpoints`.
822-
if overlap_range.is_singleton() && orig_column_count == 1 {
821+
if overlap_range.is_singleton() && matrix.column_count() == 1 {
823822
overlap_range.lint_overlapping_range_endpoints(
824823
pcx,
825824
spec_matrix.rows().map(|child_row| &matrix.rows[child_row.parent_row]).map(
@@ -831,7 +830,7 @@ fn compute_usefulness<'p, 'tcx>(
831830
)
832831
},
833832
),
834-
orig_column_count,
833+
matrix.column_count(),
835834
);
836835
}
837836
}
@@ -847,7 +846,7 @@ fn compute_usefulness<'p, 'tcx>(
847846
{
848847
let patterns = missing_ctors
849848
.iter()
850-
// We want to list only real variants.
849+
// We only list real variants.
851850
.filter(|c| !(c.is_non_exhaustive() || c.is_wildcard()))
852851
.cloned()
853852
.map(|missing_ctor| DeconstructedPat::wild_from_ctor(pcx, missing_ctor))

0 commit comments

Comments
 (0)