Skip to content

Commit 6712744

Browse files
authored
Merge pull request #236 from kornelski/track_caller
track_caller for capacity overflow panics
2 parents 0e131fd + dc33f75 commit 6712744

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/array_string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ impl<const CAP: usize> ArrayString<CAP>
201201
///
202202
/// assert_eq!(&string[..], "ab");
203203
/// ```
204+
#[track_caller]
204205
pub fn push(&mut self, c: char) {
205206
self.try_push(c).unwrap();
206207
}
@@ -252,6 +253,7 @@ impl<const CAP: usize> ArrayString<CAP>
252253
///
253254
/// assert_eq!(&string[..], "ad");
254255
/// ```
256+
#[track_caller]
255257
pub fn push_str(&mut self, s: &str) {
256258
self.try_push_str(s).unwrap()
257259
}

src/arrayvec.rs

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
7777
/// assert_eq!(&array[..], &[1, 2]);
7878
/// assert_eq!(array.capacity(), 16);
7979
/// ```
80+
#[inline]
81+
#[track_caller]
8082
pub fn new() -> ArrayVec<T, CAP> {
8183
assert_capacity_limit!(CAP);
8284
unsafe {
@@ -172,6 +174,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
172174
///
173175
/// assert_eq!(&array[..], &[1, 2]);
174176
/// ```
177+
#[track_caller]
175178
pub fn push(&mut self, element: T) {
176179
ArrayVecImpl::push(self, element)
177180
}
@@ -277,6 +280,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
277280
/// assert_eq!(&array[..], &["y", "x"]);
278281
///
279282
/// ```
283+
#[track_caller]
280284
pub fn insert(&mut self, index: usize, element: T) {
281285
self.try_insert(index, element).unwrap()
282286
}
@@ -748,6 +752,7 @@ impl<T, const CAP: usize> DerefMut for ArrayVec<T, CAP> {
748752
/// assert_eq!(array.capacity(), 3);
749753
/// ```
750754
impl<T, const CAP: usize> From<[T; CAP]> for ArrayVec<T, CAP> {
755+
#[track_caller]
751756
fn from(array: [T; CAP]) -> Self {
752757
let array = ManuallyDrop::new(array);
753758
let mut vec = <ArrayVec<T, CAP>>::new();
@@ -1011,6 +1016,7 @@ impl<T, const CAP: usize> Extend<T> for ArrayVec<T, CAP> {
10111016
/// Extend the `ArrayVec` with an iterator.
10121017
///
10131018
/// ***Panics*** if extending the vector exceeds its capacity.
1019+
#[track_caller]
10141020
fn extend<I: IntoIterator<Item=T>>(&mut self, iter: I) {
10151021
unsafe {
10161022
self.extend_from_iter::<_, true>(iter)
@@ -1020,6 +1026,7 @@ impl<T, const CAP: usize> Extend<T> for ArrayVec<T, CAP> {
10201026

10211027
#[inline(never)]
10221028
#[cold]
1029+
#[track_caller]
10231030
fn extend_panic() {
10241031
panic!("ArrayVec: capacity exceeded in extend/from_iter");
10251032
}
@@ -1031,6 +1038,7 @@ impl<T, const CAP: usize> ArrayVec<T, CAP> {
10311038
///
10321039
/// Unsafe because if CHECK is false, the length of the input is not checked.
10331040
/// The caller must ensure the length of the input fits in the capacity.
1041+
#[track_caller]
10341042
pub(crate) unsafe fn extend_from_iter<I, const CHECK: bool>(&mut self, iterable: I)
10351043
where I: IntoIterator<Item = T>
10361044
{

src/arrayvec_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub(crate) trait ArrayVecImpl {
3535
/// Return a raw mutable pointer to the vector's buffer.
3636
fn as_mut_ptr(&mut self) -> *mut Self::Item;
3737

38+
#[track_caller]
3839
fn push(&mut self, element: Self::Item) {
3940
self.try_push(element).unwrap()
4041
}

0 commit comments

Comments
 (0)