Don't collect seen
if not needed
This commit is contained in:
parent
2f4cab4d21
commit
fda0301b33
1 changed files with 11 additions and 19 deletions
|
@ -1036,30 +1036,21 @@ impl ConstructorSet {
|
||||||
where
|
where
|
||||||
'tcx: 'a,
|
'tcx: 'a,
|
||||||
{
|
{
|
||||||
let mut missing = Vec::new();
|
|
||||||
let mut present: SmallVec<[_; 1]> = SmallVec::new();
|
let mut present: SmallVec<[_; 1]> = SmallVec::new();
|
||||||
|
let mut missing = Vec::new();
|
||||||
// Constructors in `ctors`, except wildcards.
|
// Constructors in `ctors`, except wildcards.
|
||||||
let mut seen = Vec::new();
|
let mut seen = ctors.filter(|c| !(matches!(c, Opaque | Wildcard)));
|
||||||
for ctor in ctors.cloned() {
|
|
||||||
match ctor {
|
|
||||||
// Wildcards in `ctors` are irrelevant to splitting
|
|
||||||
Opaque | Wildcard => {}
|
|
||||||
_ => {
|
|
||||||
seen.push(ctor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut nonexhaustive_enum_missing_visible_variants = false;
|
let mut nonexhaustive_enum_missing_visible_variants = false;
|
||||||
match self {
|
match self {
|
||||||
ConstructorSet::Single => {
|
ConstructorSet::Single => {
|
||||||
if seen.is_empty() {
|
if seen.next().is_none() {
|
||||||
missing.push(Single);
|
missing.push(Single);
|
||||||
} else {
|
} else {
|
||||||
present.push(Single);
|
present.push(Single);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstructorSet::Variants { visible_variants, hidden_variants, non_exhaustive } => {
|
ConstructorSet::Variants { visible_variants, hidden_variants, non_exhaustive } => {
|
||||||
let seen_set: FxHashSet<_> = seen.iter().map(|c| c.as_variant().unwrap()).collect();
|
let seen_set: FxHashSet<_> = seen.map(|c| c.as_variant().unwrap()).collect();
|
||||||
let mut skipped_a_hidden_variant = false;
|
let mut skipped_a_hidden_variant = false;
|
||||||
for variant in visible_variants {
|
for variant in visible_variants {
|
||||||
let ctor = Variant(*variant);
|
let ctor = Variant(*variant);
|
||||||
|
@ -1089,15 +1080,16 @@ impl ConstructorSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstructorSet::Integers { range_1, range_2, non_exhaustive } => {
|
ConstructorSet::Integers { range_1, range_2, non_exhaustive } => {
|
||||||
let seen_ranges = seen.iter().map(|ctor| ctor.as_int_range().unwrap()).cloned();
|
let seen_ranges: Vec<_> =
|
||||||
for (seen, splitted_range) in range_1.split(seen_ranges.clone()) {
|
seen.map(|ctor| ctor.as_int_range().unwrap().clone()).collect();
|
||||||
|
for (seen, splitted_range) in range_1.split(seen_ranges.iter().cloned()) {
|
||||||
match seen {
|
match seen {
|
||||||
Presence::Unseen => missing.push(IntRange(splitted_range)),
|
Presence::Unseen => missing.push(IntRange(splitted_range)),
|
||||||
Presence::Seen => present.push(IntRange(splitted_range)),
|
Presence::Seen => present.push(IntRange(splitted_range)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(range_2) = range_2 {
|
if let Some(range_2) = range_2 {
|
||||||
for (seen, splitted_range) in range_2.split(seen_ranges) {
|
for (seen, splitted_range) in range_2.split(seen_ranges.into_iter()) {
|
||||||
match seen {
|
match seen {
|
||||||
Presence::Unseen => missing.push(IntRange(splitted_range)),
|
Presence::Unseen => missing.push(IntRange(splitted_range)),
|
||||||
Presence::Seen => present.push(IntRange(splitted_range)),
|
Presence::Seen => present.push(IntRange(splitted_range)),
|
||||||
|
@ -1110,7 +1102,7 @@ impl ConstructorSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&ConstructorSet::Slice(array_len) => {
|
&ConstructorSet::Slice(array_len) => {
|
||||||
let seen_slices = seen.iter().map(|c| c.as_slice().unwrap());
|
let seen_slices = seen.map(|c| c.as_slice().unwrap());
|
||||||
let base_slice = Slice { kind: VarLen(0, 0), array_len };
|
let base_slice = Slice { kind: VarLen(0, 0), array_len };
|
||||||
for (seen, splitted_slice) in base_slice.split(seen_slices) {
|
for (seen, splitted_slice) in base_slice.split(seen_slices) {
|
||||||
let ctor = Slice(splitted_slice);
|
let ctor = Slice(splitted_slice);
|
||||||
|
@ -1123,7 +1115,7 @@ impl ConstructorSet {
|
||||||
ConstructorSet::SliceOfEmpty => {
|
ConstructorSet::SliceOfEmpty => {
|
||||||
// Behaves essentially like `Single`.
|
// Behaves essentially like `Single`.
|
||||||
let slice = Slice(Slice::new(None, FixedLen(0)));
|
let slice = Slice(Slice::new(None, FixedLen(0)));
|
||||||
if seen.is_empty() {
|
if seen.next().is_none() {
|
||||||
missing.push(slice);
|
missing.push(slice);
|
||||||
} else {
|
} else {
|
||||||
present.push(slice);
|
present.push(slice);
|
||||||
|
@ -1132,7 +1124,7 @@ impl ConstructorSet {
|
||||||
ConstructorSet::Unlistable => {
|
ConstructorSet::Unlistable => {
|
||||||
// Since we can't list constructors, we take the ones in the column. This might list
|
// Since we can't list constructors, we take the ones in the column. This might list
|
||||||
// some constructors several times but there's not much we can do.
|
// some constructors several times but there's not much we can do.
|
||||||
present.extend(seen.iter().cloned());
|
present.extend(seen.cloned());
|
||||||
missing.push(NonExhaustive);
|
missing.push(NonExhaustive);
|
||||||
}
|
}
|
||||||
// If `exhaustive_patterns` is disabled and our scrutinee is an empty type, we cannot
|
// If `exhaustive_patterns` is disabled and our scrutinee is an empty type, we cannot
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue