Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(index)!: remove ability to index IndexVec with usize #5733

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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