Skip to content

Commit

Permalink
feat(index)!: remove ability to index IndexVec with usize
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Sep 12, 2024
1 parent d8b612c commit 48b57ea
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 33 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_index/src/idxslice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ impl<I: Idx, T> IndexSlice<I, [T]> {
} else {
let last = self.last_idx();
let split = self.split_at_mut(last);
Some((&mut split.1[0], split.0))
Some((&mut split.1[I::from_usize(0)], split.0))
}
}
}
Expand Down
26 changes: 0 additions & 26 deletions crates/oxc_index/src/indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,6 @@ impl<I: Idx, T> IdxSliceIndex<I, T> for core::ops::RangeFull {
}
}

impl private_slice_index::Sealed for usize {}
// As an ergonomic concession, implement this for `usize` as well, it's too painful without
impl<I: Idx, T> IdxSliceIndex<I, T> for usize {
type Output = T;

#[inline]
fn get(self, slice: &IndexSlice<I, [T]>) -> Option<&Self::Output> {
slice.raw.get(self)
}

#[inline]
fn get_mut(self, slice: &mut IndexSlice<I, [T]>) -> Option<&mut Self::Output> {
slice.raw.get_mut(self)
}

#[inline]
fn index(self, slice: &IndexSlice<I, [T]>) -> &Self::Output {
&slice.raw[self]
}

#[inline]
fn index_mut(self, slice: &mut IndexSlice<I, [T]>) -> &mut Self::Output {
&mut slice.raw[self]
}
}

/// This trait to function in API signatures where `Vec<T>` or `[T]` use `R:
/// RangeBounds<usize>`. There are blanket implementations for the basic range
/// types in `core::ops` for all Idx types. e.g. `Range<I: Idx>`, `RangeFrom<I:
Expand Down
6 changes: 0 additions & 6 deletions crates/oxc_index/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,6 @@ fn test_indexing() {

assert_eq!(v[IdxSz::new(3)], 3);

assert_eq!(v[3], 3); // usize is allowed.

// Make sure the types are as expected
let s: &IndexSlice<IdxSz, [i32]> = &v[..];
assert_eq!(s, &[0, 1, 2, 3, 4]);
Expand Down Expand Up @@ -490,8 +488,6 @@ fn test_indexing() {
assert_eq!(s, &[0, 1, 2, 3]);
}
assert_eq!(&mut v[IdxSz::new(3)], &mut 3);

assert_eq!(&mut v[3], &mut 3); // usize is allowed.
}

#[test]
Expand All @@ -510,7 +506,6 @@ fn test_get() {
assert_eq!(s.unwrap(), &[0, 1, 2, 3]);

assert_eq!(v.get(IdxSz::new(3)), Some(&3));
assert_eq!(v.get(3), Some(&3));
}

#[test]
Expand All @@ -527,7 +522,6 @@ fn test_get_mut() {
let s: Option<&mut IndexSlice<IdxSz, [i32]>> = v.get_mut(..=IdxSz::new(3));
assert_eq!(s.unwrap(), &[0, 1, 2, 3]);
assert_eq!(v.get_mut(IdxSz::new(3)), Some(&mut 3));
assert_eq!(v.get_mut(3), Some(&mut 3));
}

#[test]
Expand Down

0 comments on commit 48b57ea

Please sign in to comment.