Skip to content

Commit e1b8441

Browse files
committed
Require enum indices to be contiguous
1 parent 10a7aa1 commit e1b8441

File tree

2 files changed

+8
-52
lines changed

2 files changed

+8
-52
lines changed

Diff for: compiler/rustc_pattern_analysis/src/constructor.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ use std::iter::once;
155155
use smallvec::SmallVec;
156156

157157
use rustc_apfloat::ieee::{DoubleS, IeeeFloat, SingleS};
158-
use rustc_index::bit_set::GrowableBitSet;
158+
use rustc_index::bit_set::{BitSet, GrowableBitSet};
159+
use rustc_index::IndexVec;
159160

160161
use self::Constructor::*;
161162
use self::MaybeInfiniteInt::*;
162163
use self::SliceKind::*;
163164

164-
use crate::index;
165165
use crate::PatCx;
166166

167167
/// Whether we have seen a constructor in the column or not.
@@ -920,10 +920,7 @@ pub enum ConstructorSet<Cx: PatCx> {
920920
Struct { empty: bool },
921921
/// This type has the following list of constructors. If `variants` is empty and
922922
/// `non_exhaustive` is false, don't use this; use `NoConstructors` instead.
923-
Variants {
924-
variants: index::IdxContainer<Cx::VariantIdx, VariantVisibility>,
925-
non_exhaustive: bool,
926-
},
923+
Variants { variants: IndexVec<Cx::VariantIdx, VariantVisibility>, non_exhaustive: bool },
927924
/// The type is `&T`.
928925
Ref,
929926
/// The type is a union.
@@ -1025,7 +1022,7 @@ impl<Cx: PatCx> ConstructorSet<Cx> {
10251022
}
10261023
}
10271024
ConstructorSet::Variants { variants, non_exhaustive } => {
1028-
let mut seen_set = index::IdxSet::new_empty(variants.len());
1025+
let mut seen_set = BitSet::new_empty(variants.len());
10291026
for idx in seen.iter().filter_map(|c| c.as_variant()) {
10301027
seen_set.insert(idx);
10311028
}

Diff for: compiler/rustc_pattern_analysis/src/lib.rs

+4-45
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,9 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
2525

2626
use std::fmt;
2727

28-
#[cfg(feature = "rustc")]
29-
pub mod index {
30-
// Faster version when the indices of variants are `0..variants.len()`.
31-
pub use rustc_index::bit_set::BitSet as IdxSet;
32-
pub use rustc_index::Idx;
33-
pub use rustc_index::IndexVec as IdxContainer;
34-
}
35-
#[cfg(not(feature = "rustc"))]
36-
pub mod index {
37-
// Slower version when the indices of variants are something else.
38-
pub trait Idx: Copy + PartialEq + Eq + std::hash::Hash {}
39-
impl<T: Copy + PartialEq + Eq + std::hash::Hash> Idx for T {}
40-
41-
#[derive(Debug)]
42-
pub struct IdxContainer<K, V>(pub rustc_hash::FxHashMap<K, V>);
43-
impl<K: Idx, V> IdxContainer<K, V> {
44-
pub fn len(&self) -> usize {
45-
self.0.len()
46-
}
47-
pub fn iter_enumerated(&self) -> impl Iterator<Item = (K, &V)> {
48-
self.0.iter().map(|(k, v)| (*k, v))
49-
}
50-
}
51-
52-
impl<V> FromIterator<V> for IdxContainer<usize, V> {
53-
fn from_iter<T: IntoIterator<Item = V>>(iter: T) -> Self {
54-
Self(iter.into_iter().enumerate().collect())
55-
}
56-
}
57-
58-
#[derive(Debug)]
59-
pub struct IdxSet<T>(pub rustc_hash::FxHashSet<T>);
60-
impl<T: Idx> IdxSet<T> {
61-
pub fn new_empty(_len: usize) -> Self {
62-
Self(Default::default())
63-
}
64-
pub fn contains(&self, elem: T) -> bool {
65-
self.0.contains(&elem)
66-
}
67-
pub fn insert(&mut self, elem: T) {
68-
self.0.insert(elem);
69-
}
70-
}
71-
}
28+
// Re-exports to avoid rustc_index version issues.
29+
pub use rustc_index::Idx;
30+
pub use rustc_index::IndexVec;
7231

7332
#[cfg(feature = "rustc")]
7433
use rustc_middle::ty::Ty;
@@ -96,7 +55,7 @@ pub trait PatCx: Sized + fmt::Debug {
9655
/// Errors that can abort analysis.
9756
type Error: fmt::Debug;
9857
/// The index of an enum variant.
99-
type VariantIdx: Clone + index::Idx + fmt::Debug;
58+
type VariantIdx: Clone + Idx + fmt::Debug;
10059
/// A string literal
10160
type StrLit: Clone + PartialEq + fmt::Debug;
10261
/// Extra data to store in a match arm.

0 commit comments

Comments
 (0)