From 54cb1adc47a7478747dcbeb431c60387f185a57c Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Tue, 22 Nov 2022 11:26:54 -0500 Subject: [PATCH] add track caller in more locations --- src/array/ops.rs | 2 ++ src/boxed/ops.rs | 2 ++ src/slice/api.rs | 29 ++++++++++++++++++----------- src/slice/ops.rs | 1 + src/vec/ops.rs | 2 ++ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/array/ops.rs b/src/array/ops.rs index fb9012e3..540fa365 100644 --- a/src/array/ops.rs +++ b/src/array/ops.rs @@ -208,6 +208,7 @@ where type Output = as Index>::Output; #[inline] + #[track_caller] fn index(&self, index: Idx) -> &Self::Output { &self.as_bitslice()[index] } @@ -220,6 +221,7 @@ where BitSlice: IndexMut, { #[inline] + #[track_caller] fn index_mut(&mut self, index: Idx) -> &mut Self::Output { &mut self.as_mut_bitslice()[index] } diff --git a/src/boxed/ops.rs b/src/boxed/ops.rs index 74ccad77..71af06df 100644 --- a/src/boxed/ops.rs +++ b/src/boxed/ops.rs @@ -222,6 +222,7 @@ where type Output = as Index>::Output; #[inline] + #[track_caller] fn index(&self, index: Idx) -> &Self::Output { &self.as_bitslice()[index] } @@ -235,6 +236,7 @@ where BitSlice: IndexMut, { #[inline] + #[track_caller] fn index_mut(&mut self, index: Idx) -> &mut Self::Output { &mut self.as_mut_bitslice()[index] } diff --git a/src/slice/api.rs b/src/slice/api.rs index 715f1694..e62e695b 100644 --- a/src/slice/api.rs +++ b/src/slice/api.rs @@ -2589,17 +2589,22 @@ where } #[inline] + #[track_caller] fn index(self, bits: &'a BitSlice) -> 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) -> 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), + } } } @@ -2660,9 +2665,10 @@ 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] @@ -2670,9 +2676,10 @@ macro_rules! range_impl { 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), + } } } }; diff --git a/src/slice/ops.rs b/src/slice/ops.rs index 03f86ed1..e72a9ce9 100644 --- a/src/slice/ops.rs +++ b/src/slice/ops.rs @@ -155,6 +155,7 @@ where /// bits[1]; // --------^ /// ``` #[inline] + #[track_caller] fn index(&self, index: usize) -> &Self::Output { match *index.index(self) { true => &true, diff --git a/src/vec/ops.rs b/src/vec/ops.rs index 71bd36e1..9a1ab484 100644 --- a/src/vec/ops.rs +++ b/src/vec/ops.rs @@ -233,6 +233,7 @@ where type Output = as Index>::Output; #[inline] + #[track_caller] fn index(&self, index: Idx) -> &Self::Output { &self.as_bitslice()[index] } @@ -246,6 +247,7 @@ where BitSlice: IndexMut, { #[inline] + #[track_caller] fn index_mut(&mut self, index: Idx) -> &mut Self::Output { &mut self.as_mut_bitslice()[index] }