Skip to content

Commit c7f6aa2

Browse files
committed
Auto merge of #147042 - Noratrieb:untrack-caller-vec, r=tgross35
Remove most `#[track_caller]` from allocating Vec methods They cause significant binary size overhead while contributing little value. closes #146963, see that issue for more details.
2 parents 848e674 + 9316d45 commit c7f6aa2

File tree

14 files changed

+1
-122
lines changed

14 files changed

+1
-122
lines changed

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ pub struct VecDeque<
103103

104104
#[stable(feature = "rust1", since = "1.0.0")]
105105
impl<T: Clone, A: Allocator + Clone> Clone for VecDeque<T, A> {
106-
#[track_caller]
107106
fn clone(&self) -> Self {
108107
let mut deq = Self::with_capacity_in(self.len(), self.allocator().clone());
109108
deq.extend(self.iter().cloned());
@@ -114,7 +113,6 @@ impl<T: Clone, A: Allocator + Clone> Clone for VecDeque<T, A> {
114113
///
115114
/// This method is preferred over simply assigning `source.clone()` to `self`,
116115
/// as it avoids reallocation if possible.
117-
#[track_caller]
118116
fn clone_from(&mut self, source: &Self) {
119117
self.clear();
120118
self.extend(source.iter().cloned());
@@ -577,7 +575,6 @@ impl<T> VecDeque<T> {
577575
#[inline]
578576
#[stable(feature = "rust1", since = "1.0.0")]
579577
#[must_use]
580-
#[track_caller]
581578
pub fn with_capacity(capacity: usize) -> VecDeque<T> {
582579
Self::with_capacity_in(capacity, Global)
583580
}
@@ -633,7 +630,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
633630
/// let deque: VecDeque<u32> = VecDeque::with_capacity(10);
634631
/// ```
635632
#[unstable(feature = "allocator_api", issue = "32838")]
636-
#[track_caller]
637633
pub fn with_capacity_in(capacity: usize, alloc: A) -> VecDeque<T, A> {
638634
VecDeque { head: 0, len: 0, buf: RawVec::with_capacity_in(capacity, alloc) }
639635
}
@@ -799,7 +795,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
799795
///
800796
/// [`reserve`]: VecDeque::reserve
801797
#[stable(feature = "rust1", since = "1.0.0")]
802-
#[track_caller]
803798
pub fn reserve_exact(&mut self, additional: usize) {
804799
let new_cap = self.len.checked_add(additional).expect("capacity overflow");
805800
let old_cap = self.capacity();
@@ -830,7 +825,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
830825
/// ```
831826
#[stable(feature = "rust1", since = "1.0.0")]
832827
#[cfg_attr(not(test), rustc_diagnostic_item = "vecdeque_reserve")]
833-
#[track_caller]
834828
pub fn reserve(&mut self, additional: usize) {
835829
let new_cap = self.len.checked_add(additional).expect("capacity overflow");
836830
let old_cap = self.capacity();
@@ -962,7 +956,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
962956
/// assert!(buf.capacity() >= 4);
963957
/// ```
964958
#[stable(feature = "deque_extras_15", since = "1.5.0")]
965-
#[track_caller]
966959
pub fn shrink_to_fit(&mut self) {
967960
self.shrink_to(0);
968961
}
@@ -988,7 +981,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
988981
/// assert!(buf.capacity() >= 4);
989982
/// ```
990983
#[stable(feature = "shrink_to", since = "1.56.0")]
991-
#[track_caller]
992984
pub fn shrink_to(&mut self, min_capacity: usize) {
993985
let target_cap = min_capacity.max(self.len);
994986

@@ -1891,7 +1883,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
18911883
/// assert_eq!(d.front(), Some(&2));
18921884
/// ```
18931885
#[stable(feature = "rust1", since = "1.0.0")]
1894-
#[track_caller]
18951886
pub fn push_front(&mut self, value: T) {
18961887
let _ = self.push_front_mut(value);
18971888
}
@@ -1910,7 +1901,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
19101901
/// assert_eq!(d.front(), Some(&7));
19111902
/// ```
19121903
#[unstable(feature = "push_mut", issue = "135974")]
1913-
#[track_caller]
19141904
#[must_use = "if you don't need a reference to the value, use `VecDeque::push_front` instead"]
19151905
pub fn push_front_mut(&mut self, value: T) -> &mut T {
19161906
if self.is_full() {
@@ -1937,7 +1927,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
19371927
/// ```
19381928
#[stable(feature = "rust1", since = "1.0.0")]
19391929
#[rustc_confusables("push", "put", "append")]
1940-
#[track_caller]
19411930
pub fn push_back(&mut self, value: T) {
19421931
let _ = self.push_back_mut(value);
19431932
}
@@ -1956,7 +1945,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
19561945
/// assert_eq!(d.back(), Some(&10));
19571946
/// ```
19581947
#[unstable(feature = "push_mut", issue = "135974")]
1959-
#[track_caller]
19601948
#[must_use = "if you don't need a reference to the value, use `VecDeque::push_back` instead"]
19611949
pub fn push_back_mut(&mut self, value: T) -> &mut T {
19621950
if self.is_full() {
@@ -2071,7 +2059,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
20712059
/// assert_eq!(vec_deque, &['a', 'd', 'b', 'c', 'e']);
20722060
/// ```
20732061
#[stable(feature = "deque_extras_15", since = "1.5.0")]
2074-
#[track_caller]
20752062
pub fn insert(&mut self, index: usize, value: T) {
20762063
let _ = self.insert_mut(index, value);
20772064
}
@@ -2099,7 +2086,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
20992086
/// assert_eq!(vec_deque, &[1, 12, 2, 3]);
21002087
/// ```
21012088
#[unstable(feature = "push_mut", issue = "135974")]
2102-
#[track_caller]
21032089
#[must_use = "if you don't need a reference to the value, use `VecDeque::insert` instead"]
21042090
pub fn insert_mut(&mut self, index: usize, value: T) -> &mut T {
21052091
assert!(index <= self.len(), "index out of bounds");
@@ -2205,7 +2191,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
22052191
#[inline]
22062192
#[must_use = "use `.truncate()` if you don't need the other half"]
22072193
#[stable(feature = "split_off", since = "1.4.0")]
2208-
#[track_caller]
22092194
pub fn split_off(&mut self, at: usize) -> Self
22102195
where
22112196
A: Clone,
@@ -2272,7 +2257,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
22722257
/// ```
22732258
#[inline]
22742259
#[stable(feature = "append", since = "1.4.0")]
2275-
#[track_caller]
22762260
pub fn append(&mut self, other: &mut Self) {
22772261
if T::IS_ZST {
22782262
self.len = self.len.checked_add(other.len).expect("capacity overflow");
@@ -2395,7 +2379,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
23952379
// be called in cold paths.
23962380
// This may panic or abort
23972381
#[inline(never)]
2398-
#[track_caller]
23992382
fn grow(&mut self) {
24002383
// Extend or possibly remove this assertion when valid use-cases for growing the
24012384
// buffer without it being full emerge
@@ -2434,7 +2417,6 @@ impl<T, A: Allocator> VecDeque<T, A> {
24342417
/// assert_eq!(buf, [5, 10, 101, 102, 103]);
24352418
/// ```
24362419
#[stable(feature = "vec_resize_with", since = "1.33.0")]
2437-
#[track_caller]
24382420
pub fn resize_with(&mut self, new_len: usize, generator: impl FnMut() -> T) {
24392421
let len = self.len;
24402422

@@ -2981,7 +2963,6 @@ impl<T: Clone, A: Allocator> VecDeque<T, A> {
29812963
/// assert_eq!(buf, [5, 10, 20, 20, 20]);
29822964
/// ```
29832965
#[stable(feature = "deque_extras", since = "1.16.0")]
2984-
#[track_caller]
29852966
pub fn resize(&mut self, new_len: usize, value: T) {
29862967
if new_len > self.len() {
29872968
let extra = new_len - self.len();
@@ -3101,7 +3082,6 @@ impl<T, A: Allocator> IndexMut<usize> for VecDeque<T, A> {
31013082

31023083
#[stable(feature = "rust1", since = "1.0.0")]
31033084
impl<T> FromIterator<T> for VecDeque<T> {
3104-
#[track_caller]
31053085
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> VecDeque<T> {
31063086
SpecFromIter::spec_from_iter(iter.into_iter())
31073087
}
@@ -3141,19 +3121,16 @@ impl<'a, T, A: Allocator> IntoIterator for &'a mut VecDeque<T, A> {
31413121

31423122
#[stable(feature = "rust1", since = "1.0.0")]
31433123
impl<T, A: Allocator> Extend<T> for VecDeque<T, A> {
3144-
#[track_caller]
31453124
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
31463125
<Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter());
31473126
}
31483127

31493128
#[inline]
3150-
#[track_caller]
31513129
fn extend_one(&mut self, elem: T) {
31523130
self.push_back(elem);
31533131
}
31543132

31553133
#[inline]
3156-
#[track_caller]
31573134
fn extend_reserve(&mut self, additional: usize) {
31583135
self.reserve(additional);
31593136
}
@@ -3169,19 +3146,16 @@ impl<T, A: Allocator> Extend<T> for VecDeque<T, A> {
31693146

31703147
#[stable(feature = "extend_ref", since = "1.2.0")]
31713148
impl<'a, T: 'a + Copy, A: Allocator> Extend<&'a T> for VecDeque<T, A> {
3172-
#[track_caller]
31733149
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
31743150
self.spec_extend(iter.into_iter());
31753151
}
31763152

31773153
#[inline]
3178-
#[track_caller]
31793154
fn extend_one(&mut self, &elem: &'a T) {
31803155
self.push_back(elem);
31813156
}
31823157

31833158
#[inline]
3184-
#[track_caller]
31853159
fn extend_reserve(&mut self, additional: usize) {
31863160
self.reserve(additional);
31873161
}
@@ -3279,7 +3253,6 @@ impl<T, const N: usize> From<[T; N]> for VecDeque<T> {
32793253
/// let deq2: VecDeque<_> = [1, 2, 3, 4].into();
32803254
/// assert_eq!(deq1, deq2);
32813255
/// ```
3282-
#[track_caller]
32833256
fn from(arr: [T; N]) -> Self {
32843257
let mut deq = VecDeque::with_capacity(N);
32853258
let arr = ManuallyDrop::new(arr);

library/alloc/src/collections/vec_deque/spec_extend.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ use crate::vec;
88

99
// Specialization trait used for VecDeque::extend
1010
pub(super) trait SpecExtend<T, I> {
11-
#[track_caller]
1211
fn spec_extend(&mut self, iter: I);
1312
}
1413

1514
impl<T, I, A: Allocator> SpecExtend<T, I> for VecDeque<T, A>
1615
where
1716
I: Iterator<Item = T>,
1817
{
19-
#[track_caller]
2018
default fn spec_extend(&mut self, mut iter: I) {
2119
// This function should be the moral equivalent of:
2220
//
@@ -47,7 +45,6 @@ impl<T, I, A: Allocator> SpecExtend<T, I> for VecDeque<T, A>
4745
where
4846
I: TrustedLen<Item = T>,
4947
{
50-
#[track_caller]
5148
default fn spec_extend(&mut self, iter: I) {
5249
// This is the case for a TrustedLen iterator.
5350
let (low, high) = iter.size_hint();
@@ -81,7 +78,6 @@ where
8178

8279
#[cfg(not(test))]
8380
impl<T, A: Allocator> SpecExtend<T, vec::IntoIter<T>> for VecDeque<T, A> {
84-
#[track_caller]
8581
fn spec_extend(&mut self, mut iterator: vec::IntoIter<T>) {
8682
let slice = iterator.as_slice();
8783
self.reserve(slice.len());
@@ -99,7 +95,6 @@ where
9995
I: Iterator<Item = &'a T>,
10096
T: Copy,
10197
{
102-
#[track_caller]
10398
default fn spec_extend(&mut self, iterator: I) {
10499
self.spec_extend(iterator.copied())
105100
}
@@ -109,7 +104,6 @@ impl<'a, T: 'a, A: Allocator> SpecExtend<&'a T, slice::Iter<'a, T>> for VecDeque
109104
where
110105
T: Copy,
111106
{
112-
#[track_caller]
113107
fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) {
114108
let slice = iterator.as_slice();
115109
self.reserve(slice.len());

library/alloc/src/collections/vec_deque/spec_from_iter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ impl<T, I> SpecFromIter<T, I> for VecDeque<T>
99
where
1010
I: Iterator<Item = T>,
1111
{
12-
#[track_caller]
1312
default fn spec_from_iter(iterator: I) -> Self {
1413
// Since converting is O(1) now, just re-use the `Vec` logic for
1514
// anything where we can't do something extra-special for `VecDeque`,

library/alloc/src/raw_vec/mod.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ mod tests;
2424
// only one location which panics rather than a bunch throughout the module.
2525
#[cfg(not(no_global_oom_handling))]
2626
#[cfg_attr(not(panic = "immediate-abort"), inline(never))]
27-
#[track_caller]
2827
fn capacity_overflow() -> ! {
2928
panic!("capacity overflow");
3029
}
@@ -123,7 +122,6 @@ impl<T> RawVec<T, Global> {
123122
#[cfg(not(any(no_global_oom_handling, test)))]
124123
#[must_use]
125124
#[inline]
126-
#[track_caller]
127125
pub(crate) fn with_capacity(capacity: usize) -> Self {
128126
Self { inner: RawVecInner::with_capacity(capacity, T::LAYOUT), _marker: PhantomData }
129127
}
@@ -132,7 +130,6 @@ impl<T> RawVec<T, Global> {
132130
#[cfg(not(any(no_global_oom_handling, test)))]
133131
#[must_use]
134132
#[inline]
135-
#[track_caller]
136133
pub(crate) fn with_capacity_zeroed(capacity: usize) -> Self {
137134
Self {
138135
inner: RawVecInner::with_capacity_zeroed_in(capacity, Global, T::LAYOUT),
@@ -145,7 +142,6 @@ impl RawVecInner<Global> {
145142
#[cfg(not(any(no_global_oom_handling, test)))]
146143
#[must_use]
147144
#[inline]
148-
#[track_caller]
149145
fn with_capacity(capacity: usize, elem_layout: Layout) -> Self {
150146
match Self::try_allocate_in(capacity, AllocInit::Uninitialized, Global, elem_layout) {
151147
Ok(res) => res,
@@ -186,7 +182,6 @@ impl<T, A: Allocator> RawVec<T, A> {
186182
/// allocator for the returned `RawVec`.
187183
#[cfg(not(no_global_oom_handling))]
188184
#[inline]
189-
#[track_caller]
190185
pub(crate) fn with_capacity_in(capacity: usize, alloc: A) -> Self {
191186
Self {
192187
inner: RawVecInner::with_capacity_in(capacity, alloc, T::LAYOUT),
@@ -208,7 +203,6 @@ impl<T, A: Allocator> RawVec<T, A> {
208203
/// of allocator for the returned `RawVec`.
209204
#[cfg(not(no_global_oom_handling))]
210205
#[inline]
211-
#[track_caller]
212206
pub(crate) fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self {
213207
Self {
214208
inner: RawVecInner::with_capacity_zeroed_in(capacity, alloc, T::LAYOUT),
@@ -328,7 +322,6 @@ impl<T, A: Allocator> RawVec<T, A> {
328322
/// Aborts on OOM.
329323
#[cfg(not(no_global_oom_handling))]
330324
#[inline]
331-
#[track_caller]
332325
pub(crate) fn reserve(&mut self, len: usize, additional: usize) {
333326
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
334327
unsafe { self.inner.reserve(len, additional, T::LAYOUT) }
@@ -338,7 +331,6 @@ impl<T, A: Allocator> RawVec<T, A> {
338331
/// caller to ensure `len == self.capacity()`.
339332
#[cfg(not(no_global_oom_handling))]
340333
#[inline(never)]
341-
#[track_caller]
342334
pub(crate) fn grow_one(&mut self) {
343335
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
344336
unsafe { self.inner.grow_one(T::LAYOUT) }
@@ -372,7 +364,6 @@ impl<T, A: Allocator> RawVec<T, A> {
372364
///
373365
/// Aborts on OOM.
374366
#[cfg(not(no_global_oom_handling))]
375-
#[track_caller]
376367
pub(crate) fn reserve_exact(&mut self, len: usize, additional: usize) {
377368
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
378369
unsafe { self.inner.reserve_exact(len, additional, T::LAYOUT) }
@@ -399,7 +390,6 @@ impl<T, A: Allocator> RawVec<T, A> {
399390
///
400391
/// Aborts on OOM.
401392
#[cfg(not(no_global_oom_handling))]
402-
#[track_caller]
403393
#[inline]
404394
pub(crate) fn shrink_to_fit(&mut self, cap: usize) {
405395
// SAFETY: All calls on self.inner pass T::LAYOUT as the elem_layout
@@ -425,7 +415,6 @@ impl<A: Allocator> RawVecInner<A> {
425415

426416
#[cfg(not(no_global_oom_handling))]
427417
#[inline]
428-
#[track_caller]
429418
fn with_capacity_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self {
430419
match Self::try_allocate_in(capacity, AllocInit::Uninitialized, alloc, elem_layout) {
431420
Ok(this) => {
@@ -450,7 +439,6 @@ impl<A: Allocator> RawVecInner<A> {
450439

451440
#[cfg(not(no_global_oom_handling))]
452441
#[inline]
453-
#[track_caller]
454442
fn with_capacity_zeroed_in(capacity: usize, alloc: A, elem_layout: Layout) -> Self {
455443
match Self::try_allocate_in(capacity, AllocInit::Zeroed, alloc, elem_layout) {
456444
Ok(res) => res,
@@ -553,7 +541,6 @@ impl<A: Allocator> RawVecInner<A> {
553541
/// - `elem_layout`'s size must be a multiple of its alignment
554542
#[cfg(not(no_global_oom_handling))]
555543
#[inline]
556-
#[track_caller]
557544
unsafe fn reserve(&mut self, len: usize, additional: usize, elem_layout: Layout) {
558545
// Callers expect this function to be very cheap when there is already sufficient capacity.
559546
// Therefore, we move all the resizing and error-handling logic from grow_amortized and
@@ -585,7 +572,6 @@ impl<A: Allocator> RawVecInner<A> {
585572
/// - `elem_layout`'s size must be a multiple of its alignment
586573
#[cfg(not(no_global_oom_handling))]
587574
#[inline]
588-
#[track_caller]
589575
unsafe fn grow_one(&mut self, elem_layout: Layout) {
590576
// SAFETY: Precondition passed to caller
591577
if let Err(err) = unsafe { self.grow_amortized(self.cap.as_inner(), 1, elem_layout) } {
@@ -621,7 +607,6 @@ impl<A: Allocator> RawVecInner<A> {
621607
/// initially construct `self`
622608
/// - `elem_layout`'s size must be a multiple of its alignment
623609
#[cfg(not(no_global_oom_handling))]
624-
#[track_caller]
625610
unsafe fn reserve_exact(&mut self, len: usize, additional: usize, elem_layout: Layout) {
626611
// SAFETY: Precondition passed to caller
627612
if let Err(err) = unsafe { self.try_reserve_exact(len, additional, elem_layout) } {
@@ -659,7 +644,6 @@ impl<A: Allocator> RawVecInner<A> {
659644
/// - `cap` must be less than or equal to `self.capacity(elem_layout.size())`
660645
#[cfg(not(no_global_oom_handling))]
661646
#[inline]
662-
#[track_caller]
663647
unsafe fn shrink_to_fit(&mut self, cap: usize, elem_layout: Layout) {
664648
if let Err(err) = unsafe { self.shrink(cap, elem_layout) } {
665649
handle_error(err);
@@ -872,7 +856,6 @@ where
872856
#[cfg(not(no_global_oom_handling))]
873857
#[cold]
874858
#[optimize(size)]
875-
#[track_caller]
876859
fn handle_error(e: TryReserveError) -> ! {
877860
match e.kind() {
878861
CapacityOverflow => capacity_overflow(),

0 commit comments

Comments
 (0)