Skip to content

Commit 7d10238

Browse files
committed
Add doc aliases for memory allocations
- Vec::with_capacity / Box::new -> alloc + malloc - Box::new_zeroed -> calloc - Vec::{reserve,reserve_exact,try_reserve_exact,shrink_to_fit,shrink_to} -> realloc
1 parent bbc01bb commit 7d10238

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

library/alloc/src/boxed.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ impl<T> Box<T> {
178178
/// ```
179179
/// let five = Box::new(5);
180180
/// ```
181-
#[stable(feature = "rust1", since = "1.0.0")]
182181
#[inline(always)]
182+
#[doc(alias = "alloc")]
183+
#[doc(alias = "malloc")]
184+
#[stable(feature = "rust1", since = "1.0.0")]
183185
pub fn new(x: T) -> Self {
184186
box x
185187
}
@@ -226,8 +228,9 @@ impl<T> Box<T> {
226228
/// ```
227229
///
228230
/// [zeroed]: mem::MaybeUninit::zeroed
229-
#[unstable(feature = "new_uninit", issue = "63291")]
230231
#[inline]
232+
#[doc(alias = "calloc")]
233+
#[unstable(feature = "new_uninit", issue = "63291")]
231234
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
232235
Self::new_zeroed_in(Global)
233236
}

library/alloc/src/macros.rs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
///
3636
/// [`Vec`]: crate::vec::Vec
3737
#[cfg(not(test))]
38+
#[doc(alias = "alloc")]
39+
#[doc(alias = "malloc")]
3840
#[macro_export]
3941
#[stable(feature = "rust1", since = "1.0.0")]
4042
#[allow_internal_unstable(box_syntax, liballoc_internals)]

library/alloc/src/string.rs

+2
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,8 @@ impl String {
403403
/// s.push('a');
404404
/// ```
405405
#[inline]
406+
#[doc(alias = "alloc")]
407+
#[doc(alias = "malloc")]
406408
#[stable(feature = "rust1", since = "1.0.0")]
407409
pub fn with_capacity(capacity: usize) -> String {
408410
String { vec: Vec::with_capacity(capacity) }

library/alloc/src/vec/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ impl<T> Vec<T> {
433433
/// assert!(vec.capacity() >= 11);
434434
/// ```
435435
#[inline]
436+
#[doc(alias = "malloc")]
436437
#[stable(feature = "rust1", since = "1.0.0")]
437438
pub fn with_capacity(capacity: usize) -> Self {
438439
Self::with_capacity_in(capacity, Global)
@@ -766,6 +767,7 @@ impl<T, A: Allocator> Vec<T, A> {
766767
/// vec.reserve(10);
767768
/// assert!(vec.capacity() >= 11);
768769
/// ```
770+
#[doc(alias = "realloc")]
769771
#[stable(feature = "rust1", since = "1.0.0")]
770772
pub fn reserve(&mut self, additional: usize) {
771773
self.buf.reserve(self.len, additional);
@@ -791,6 +793,7 @@ impl<T, A: Allocator> Vec<T, A> {
791793
/// vec.reserve_exact(10);
792794
/// assert!(vec.capacity() >= 11);
793795
/// ```
796+
#[doc(alias = "realloc")]
794797
#[stable(feature = "rust1", since = "1.0.0")]
795798
pub fn reserve_exact(&mut self, additional: usize) {
796799
self.buf.reserve_exact(self.len, additional);
@@ -828,6 +831,7 @@ impl<T, A: Allocator> Vec<T, A> {
828831
/// }
829832
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
830833
/// ```
834+
#[doc(alias = "realloc")]
831835
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
832836
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
833837
self.buf.try_reserve(self.len, additional)
@@ -869,6 +873,7 @@ impl<T, A: Allocator> Vec<T, A> {
869873
/// }
870874
/// # process_data(&[1, 2, 3]).expect("why is the test harness OOMing on 12 bytes?");
871875
/// ```
876+
#[doc(alias = "realloc")]
872877
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
873878
pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
874879
self.buf.try_reserve_exact(self.len, additional)
@@ -888,6 +893,7 @@ impl<T, A: Allocator> Vec<T, A> {
888893
/// vec.shrink_to_fit();
889894
/// assert!(vec.capacity() >= 3);
890895
/// ```
896+
#[doc(alias = "realloc")]
891897
#[stable(feature = "rust1", since = "1.0.0")]
892898
pub fn shrink_to_fit(&mut self) {
893899
// The capacity is never less than the length, and there's nothing to do when
@@ -920,6 +926,7 @@ impl<T, A: Allocator> Vec<T, A> {
920926
/// vec.shrink_to(0);
921927
/// assert!(vec.capacity() >= 3);
922928
/// ```
929+
#[doc(alias = "realloc")]
923930
#[unstable(feature = "shrink_to", reason = "new API", issue = "56431")]
924931
pub fn shrink_to(&mut self, min_capacity: usize) {
925932
self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));

0 commit comments

Comments
 (0)