Skip to content

Commit 7b16d2c

Browse files
committed
add track_caller
1 parent b86674e commit 7b16d2c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

library/alloc/src/vec/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ impl<T, A: Allocator> Vec<T, A> {
769769
/// assert!(vec.capacity() >= 11);
770770
/// ```
771771
#[doc(alias = "realloc")]
772+
#[track_caller]
772773
#[stable(feature = "rust1", since = "1.0.0")]
773774
pub fn reserve(&mut self, additional: usize) {
774775
self.buf.reserve(self.len, additional);
@@ -795,6 +796,7 @@ impl<T, A: Allocator> Vec<T, A> {
795796
/// assert!(vec.capacity() >= 11);
796797
/// ```
797798
#[doc(alias = "realloc")]
799+
#[track_caller]
798800
#[stable(feature = "rust1", since = "1.0.0")]
799801
pub fn reserve_exact(&mut self, additional: usize) {
800802
self.buf.reserve_exact(self.len, additional);
@@ -895,6 +897,7 @@ impl<T, A: Allocator> Vec<T, A> {
895897
/// assert!(vec.capacity() >= 3);
896898
/// ```
897899
#[doc(alias = "realloc")]
900+
#[track_caller]
898901
#[stable(feature = "rust1", since = "1.0.0")]
899902
pub fn shrink_to_fit(&mut self) {
900903
// The capacity is never less than the length, and there's nothing to do when
@@ -925,6 +928,7 @@ impl<T, A: Allocator> Vec<T, A> {
925928
/// assert!(vec.capacity() >= 3);
926929
/// ```
927930
#[doc(alias = "realloc")]
931+
#[track_caller]
928932
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
929933
pub fn shrink_to(&mut self, min_capacity: usize) {
930934
if self.capacity() > min_capacity {
@@ -956,6 +960,7 @@ impl<T, A: Allocator> Vec<T, A> {
956960
/// let slice = vec.into_boxed_slice();
957961
/// assert_eq!(slice.into_vec().capacity(), 3);
958962
/// ```
963+
#[track_caller]
959964
#[stable(feature = "rust1", since = "1.0.0")]
960965
pub fn into_boxed_slice(mut self) -> Box<[T], A> {
961966
unsafe {
@@ -1539,6 +1544,7 @@ impl<T, A: Allocator> Vec<T, A> {
15391544
/// assert_eq!(vec, [1, 2, 3]);
15401545
/// ```
15411546
#[inline]
1547+
#[track_caller]
15421548
#[stable(feature = "rust1", since = "1.0.0")]
15431549
pub fn push(&mut self, value: T) {
15441550
// This will panic or abort if we would allocate > isize::MAX bytes
@@ -1592,6 +1598,7 @@ impl<T, A: Allocator> Vec<T, A> {
15921598
/// assert_eq!(vec2, []);
15931599
/// ```
15941600
#[inline]
1601+
#[track_caller]
15951602
#[stable(feature = "append", since = "1.4.0")]
15961603
pub fn append(&mut self, other: &mut Self) {
15971604
unsafe {
@@ -1602,6 +1609,7 @@ impl<T, A: Allocator> Vec<T, A> {
16021609

16031610
/// Appends elements to `Self` from other buffer.
16041611
#[inline]
1612+
#[track_caller]
16051613
unsafe fn append_elements(&mut self, other: *const [T]) {
16061614
let count = unsafe { (*other).len() };
16071615
self.reserve(count);
@@ -2009,6 +2017,7 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
20092017
/// ```
20102018
///
20112019
/// [`extend`]: Vec::extend
2020+
#[track_caller]
20122021
#[stable(feature = "vec_extend_from_slice", since = "1.6.0")]
20132022
pub fn extend_from_slice(&mut self, other: &[T]) {
20142023
self.spec_extend(other.iter())
@@ -2086,6 +2095,7 @@ impl<T, F: FnMut() -> T> ExtendWith<T> for ExtendFunc<F> {
20862095

20872096
impl<T, A: Allocator> Vec<T, A> {
20882097
/// Extend the vector by `n` values, using the given generator.
2098+
#[track_caller]
20892099
fn extend_with<E: ExtendWith<T>>(&mut self, n: usize, mut value: E) {
20902100
self.reserve(n);
20912101

@@ -2298,6 +2308,7 @@ impl<T, I: SliceIndex<[T]>, A: Allocator> IndexMut<I> for Vec<T, A> {
22982308
#[stable(feature = "rust1", since = "1.0.0")]
22992309
impl<T> FromIterator<T> for Vec<T> {
23002310
#[inline]
2311+
#[track_caller]
23012312
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T> {
23022313
<Self as SpecFromIter<T, I::IntoIter>>::from_iter(iter.into_iter())
23032314
}
@@ -2386,6 +2397,7 @@ impl<T, A: Allocator> Extend<T> for Vec<T, A> {
23862397
impl<T, A: Allocator> Vec<T, A> {
23872398
// leaf method to which various SpecFrom/SpecExtend implementations delegate when
23882399
// they have no further optimizations to apply
2400+
#[track_caller]
23892401
fn extend_desugared<I: Iterator<Item = T>>(&mut self, mut iterator: I) {
23902402
// This is the case for a general iterator.
23912403
//
@@ -2517,18 +2529,22 @@ impl<T, A: Allocator> Vec<T, A> {
25172529
/// append the entire slice at once.
25182530
///
25192531
/// [`copy_from_slice`]: ../../std/primitive.slice.html#method.copy_from_slice
2532+
/// [`copy_from_slice`]: slice::copy_from_slice
25202533
#[stable(feature = "extend_ref", since = "1.2.0")]
25212534
impl<'a, T: Copy + 'a, A: Allocator + 'a> Extend<&'a T> for Vec<T, A> {
2535+
#[track_caller]
25222536
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
25232537
self.spec_extend(iter.into_iter())
25242538
}
25252539

25262540
#[inline]
2541+
#[track_caller]
25272542
fn extend_one(&mut self, &item: &'a T) {
25282543
self.push(item);
25292544
}
25302545

25312546
#[inline]
2547+
#[track_caller]
25322548
fn extend_reserve(&mut self, additional: usize) {
25332549
self.reserve(additional);
25342550
}

library/alloc/src/vec/spec_extend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
1414
where
1515
I: Iterator<Item = T>,
1616
{
17+
#[track_caller]
1718
default fn spec_extend(&mut self, iter: I) {
1819
self.extend_desugared(iter)
1920
}
@@ -23,6 +24,7 @@ impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
2324
where
2425
I: TrustedLen<Item = T>,
2526
{
27+
#[track_caller]
2628
default fn spec_extend(&mut self, iterator: I) {
2729
// This is the case for a TrustedLen iterator.
2830
let (low, high) = iterator.size_hint();

library/alloc/src/vec/spec_from_iter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ where
3838
}
3939

4040
impl<T> SpecFromIter<T, IntoIter<T>> for Vec<T> {
41+
#[track_caller]
4142
fn from_iter(iterator: IntoIter<T>) -> Self {
4243
// A common case is passing a vector into a function which immediately
4344
// re-collects into a vector. We can short circuit this if the IntoIter
@@ -71,6 +72,7 @@ where
7172
I: Iterator<Item = &'a T>,
7273
T: Clone,
7374
{
75+
#[track_caller]
7476
default fn from_iter(iterator: I) -> Self {
7577
SpecFromIter::from_iter(iterator.cloned())
7678
}

0 commit comments

Comments
 (0)