Skip to content

Commit 5fb8550

Browse files
authored
Merge pull request #201 from connorskees/feat/add-track-caller
Add `#[track_caller]` in more locations
2 parents b6650fb + 54cb1ad commit 5fb8550

5 files changed

Lines changed: 25 additions & 11 deletions

File tree

src/array/ops.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ where
208208
type Output = <BitSlice<A::Store, O> as Index<Idx>>::Output;
209209

210210
#[inline]
211+
#[track_caller]
211212
fn index(&self, index: Idx) -> &Self::Output {
212213
&self.as_bitslice()[index]
213214
}
@@ -220,6 +221,7 @@ where
220221
BitSlice<A::Store, O>: IndexMut<Idx>,
221222
{
222223
#[inline]
224+
#[track_caller]
223225
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
224226
&mut self.as_mut_bitslice()[index]
225227
}

src/boxed/ops.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ where
222222
type Output = <BitSlice<T, O> as Index<Idx>>::Output;
223223

224224
#[inline]
225+
#[track_caller]
225226
fn index(&self, index: Idx) -> &Self::Output {
226227
&self.as_bitslice()[index]
227228
}
@@ -235,6 +236,7 @@ where
235236
BitSlice<T, O>: IndexMut<Idx>,
236237
{
237238
#[inline]
239+
#[track_caller]
238240
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
239241
&mut self.as_mut_bitslice()[index]
240242
}

src/slice/api.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,17 +2589,22 @@ where
25892589
}
25902590

25912591
#[inline]
2592+
#[track_caller]
25922593
fn index(self, bits: &'a BitSlice<T, O>) -> Self::Immut {
2593-
self.get(bits).unwrap_or_else(|| {
2594-
panic!("index {} out of bounds: {}", self, bits.len())
2595-
})
2594+
match self.get(bits) {
2595+
Some(b) => b,
2596+
None => panic!("index {} out of bounds: {}", self, bits.len())
2597+
}
25962598
}
25972599

25982600
#[inline]
2601+
#[track_caller]
25992602
fn index_mut(self, bits: &'a mut BitSlice<T, O>) -> Self::Mut {
26002603
let len = bits.len();
2601-
self.get_mut(bits)
2602-
.unwrap_or_else(|| panic!("index {} out of bounds: {}", self, len))
2604+
match self.get_mut(bits) {
2605+
Some(b) => b,
2606+
None => panic!("index {} out of bounds: {}", self, len),
2607+
}
26032608
}
26042609
}
26052610

@@ -2660,19 +2665,21 @@ macro_rules! range_impl {
26602665
fn index(self, bits: Self::Immut) -> Self::Immut {
26612666
let r = self.clone();
26622667
let l = bits.len();
2663-
self.get(bits).unwrap_or_else(|| {
2664-
panic!("range {:?} out of bounds: {}", r, l)
2665-
})
2668+
match self.get(bits) {
2669+
Some(b) => b,
2670+
None => panic!("range {:?} out of bounds: {}", r, l),
2671+
}
26662672
}
26672673

26682674
#[inline]
26692675
#[track_caller]
26702676
fn index_mut(self, bits: Self::Mut) -> Self::Mut {
26712677
let r = self.clone();
26722678
let l = bits.len();
2673-
self.get_mut(bits).unwrap_or_else(|| {
2674-
panic!("range {:?} out of bounds: {}", r, l)
2675-
})
2679+
match self.get_mut(bits) {
2680+
Some(b) => b,
2681+
None => panic!("range {:?} out of bounds: {}", r, l),
2682+
}
26762683
}
26772684
}
26782685
};

src/slice/ops.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ where
155155
/// bits[1]; // --------^
156156
/// ```
157157
#[inline]
158+
#[track_caller]
158159
fn index(&self, index: usize) -> &Self::Output {
159160
match *index.index(self) {
160161
true => &true,

src/vec/ops.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ where
233233
type Output = <BitSlice<T, O> as Index<Idx>>::Output;
234234

235235
#[inline]
236+
#[track_caller]
236237
fn index(&self, index: Idx) -> &Self::Output {
237238
&self.as_bitslice()[index]
238239
}
@@ -246,6 +247,7 @@ where
246247
BitSlice<T, O>: IndexMut<Idx>,
247248
{
248249
#[inline]
250+
#[track_caller]
249251
fn index_mut(&mut self, index: Idx) -> &mut Self::Output {
250252
&mut self.as_mut_bitslice()[index]
251253
}

0 commit comments

Comments
 (0)