Skip to content

Commit 9c116c7

Browse files
committed
add track_caller to vector
1 parent 61edfd5 commit 9c116c7

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

library/alloc/src/raw_vec.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "none")]
1+
wwwwwww#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "none")]
22
#![doc(hidden)]
33

44
use core::alloc::LayoutError;
@@ -138,13 +138,15 @@ impl<T, A: Allocator> RawVec<T, A> {
138138
/// Like `with_capacity`, but parameterized over the choice of
139139
/// allocator for the returned `RawVec`.
140140
#[inline]
141+
#[track_caller]
141142
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
142143
Self::allocate_in(capacity, AllocInit::Uninitialized, alloc)
143144
}
144145

145146
/// Like `with_capacity_zeroed`, but parameterized over the choice
146147
/// of allocator for the returned `RawVec`.
147148
#[inline]
149+
#[track_caller]
148150
pub fn with_capacity_zeroed_in(capacity: usize, alloc: A) -> Self {
149151
Self::allocate_in(capacity, AllocInit::Zeroed, alloc)
150152
}
@@ -183,6 +185,7 @@ impl<T, A: Allocator> RawVec<T, A> {
183185
}
184186
}
185187

188+
#[track_caller]
186189
fn allocate_in(capacity: usize, init: AllocInit, alloc: A) -> Self {
187190
if mem::size_of::<T>() == 0 {
188191
Self::new_in(alloc)
@@ -315,6 +318,7 @@ impl<T, A: Allocator> RawVec<T, A> {
315318
/// # vector.push_all(&[1, 3, 5, 7, 9]);
316319
/// # }
317320
/// ```
321+
#[track_caller]
318322
pub fn reserve(&mut self, len: usize, additional: usize) {
319323
handle_reserve(self.try_reserve(len, additional));
320324
}
@@ -345,6 +349,7 @@ impl<T, A: Allocator> RawVec<T, A> {
345349
/// # Aborts
346350
///
347351
/// Aborts on OOM.
352+
#[track_caller]
348353
pub fn reserve_exact(&mut self, len: usize, additional: usize) {
349354
handle_reserve(self.try_reserve_exact(len, additional));
350355
}
@@ -368,6 +373,7 @@ impl<T, A: Allocator> RawVec<T, A> {
368373
/// # Aborts
369374
///
370375
/// Aborts on OOM.
376+
#[track_caller]
371377
pub fn shrink_to_fit(&mut self, amount: usize) {
372378
handle_reserve(self.shrink(amount));
373379
}
@@ -503,6 +509,7 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec<T, A> {
503509

504510
// Central function for reserve error handling.
505511
#[inline]
512+
#[track_caller]
506513
fn handle_reserve(result: Result<(), TryReserveError>) {
507514
match result {
508515
Err(CapacityOverflow) => capacity_overflow(),
@@ -532,6 +539,7 @@ fn alloc_guard(alloc_size: usize) -> Result<(), TryReserveError> {
532539
// One central function responsible for reporting capacity overflows. This'll
533540
// ensure that the code generation related to these panics is minimal as there's
534541
// only one location which panics rather than a bunch throughout the module.
542+
#[track_caller]
535543
fn capacity_overflow() -> ! {
536544
panic!("capacity overflow");
537545
}

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)