Skip to content

Commit

Permalink
Merge pull request #201 from connorskees/feat/add-track-caller
Browse files Browse the repository at this point in the history
Add `#[track_caller]` in more locations
  • Loading branch information
myrrlyn committed Apr 12, 2023
2 parents b6650fb + 54cb1ad commit 5fb8550
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/array/ops.rs
Expand Up @@ -208,6 +208,7 @@ where
type Output = <BitSlice<A::Store, O> as Index<Idx>>::Output;

#[inline]
#[track_caller]
fn index(&self, index: Idx) -> &Self::Output {
&self.as_bitslice()[index]
}
Expand All @@ -220,6 +221,7 @@ where
BitSlice<A::Store, O>: IndexMut<Idx>,
{
#[inline]
#[track_caller]
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
&mut self.as_mut_bitslice()[index]
}
Expand Down
2 changes: 2 additions & 0 deletions src/boxed/ops.rs
Expand Up @@ -222,6 +222,7 @@ where
type Output = <BitSlice<T, O> as Index<Idx>>::Output;

#[inline]
#[track_caller]
fn index(&self, index: Idx) -> &Self::Output {
&self.as_bitslice()[index]
}
Expand All @@ -235,6 +236,7 @@ where
BitSlice<T, O>: IndexMut<Idx>,
{
#[inline]
#[track_caller]
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
&mut self.as_mut_bitslice()[index]
}
Expand Down
29 changes: 18 additions & 11 deletions src/slice/api.rs
Expand Up @@ -2589,17 +2589,22 @@ where
}

#[inline]
#[track_caller]
fn index(self, bits: &'a BitSlice<T, O>) -> Self::Immut {
self.get(bits).unwrap_or_else(|| {
panic!("index {} out of bounds: {}", self, bits.len())
})
match self.get(bits) {
Some(b) => b,
None => panic!("index {} out of bounds: {}", self, bits.len())
}
}

#[inline]
#[track_caller]
fn index_mut(self, bits: &'a mut BitSlice<T, O>) -> Self::Mut {
let len = bits.len();
self.get_mut(bits)
.unwrap_or_else(|| panic!("index {} out of bounds: {}", self, len))
match self.get_mut(bits) {
Some(b) => b,
None => panic!("index {} out of bounds: {}", self, len),
}
}
}

Expand Down Expand Up @@ -2660,19 +2665,21 @@ macro_rules! range_impl {
fn index(self, bits: Self::Immut) -> Self::Immut {
let r = self.clone();
let l = bits.len();
self.get(bits).unwrap_or_else(|| {
panic!("range {:?} out of bounds: {}", r, l)
})
match self.get(bits) {
Some(b) => b,
None => panic!("range {:?} out of bounds: {}", r, l),
}
}

#[inline]
#[track_caller]
fn index_mut(self, bits: Self::Mut) -> Self::Mut {
let r = self.clone();
let l = bits.len();
self.get_mut(bits).unwrap_or_else(|| {
panic!("range {:?} out of bounds: {}", r, l)
})
match self.get_mut(bits) {
Some(b) => b,
None => panic!("range {:?} out of bounds: {}", r, l),
}
}
}
};
Expand Down
1 change: 1 addition & 0 deletions src/slice/ops.rs
Expand Up @@ -155,6 +155,7 @@ where
/// bits[1]; // --------^
/// ```
#[inline]
#[track_caller]
fn index(&self, index: usize) -> &Self::Output {
match *index.index(self) {
true => &true,
Expand Down
2 changes: 2 additions & 0 deletions src/vec/ops.rs
Expand Up @@ -233,6 +233,7 @@ where
type Output = <BitSlice<T, O> as Index<Idx>>::Output;

#[inline]
#[track_caller]
fn index(&self, index: Idx) -> &Self::Output {
&self.as_bitslice()[index]
}
Expand All @@ -246,6 +247,7 @@ where
BitSlice<T, O>: IndexMut<Idx>,
{
#[inline]
#[track_caller]
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
&mut self.as_mut_bitslice()[index]
}
Expand Down

0 comments on commit 5fb8550

Please sign in to comment.