Skip to content

Commit 7f0d54d

Browse files
committed
More alloc docs tweaks
1 parent 9dcb64f commit 7f0d54d

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Diff for: src/liballoc/alloc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
184184
///
185185
/// The default behavior of this function is to print a message to standard error
186186
/// and abort the process.
187-
/// It can be replaced with [`std::alloc::set_oom_hook`]
188-
/// and [`std::alloc::take_oom_hook`].
187+
/// It can be replaced with [`set_oom_hook`] and [`take_oom_hook`].
188+
///
189+
/// [`set_oom_hook`]: ../../std/alloc/fn.set_oom_hook.html
190+
/// [`take_oom_hook`]: ../../std/alloc/fn.take_oom_hook.html
189191
#[stable(feature = "global_alloc", since = "1.28.0")]
190192
#[rustc_allocator_nounwind]
191193
pub fn oom(layout: Layout) -> ! {

Diff for: src/libcore/alloc.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ pub unsafe trait GlobalAlloc {
494494
/// Clients wishing to abort computation in response to an
495495
/// allocation error are encouraged to call the [`oom`] function,
496496
/// rather than directly invoking `panic!` or similar.
497+
///
498+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
497499
#[stable(feature = "global_alloc", since = "1.28.0")]
498500
unsafe fn alloc(&self, layout: Layout) -> *mut u8;
499501

@@ -529,6 +531,8 @@ pub unsafe trait GlobalAlloc {
529531
/// Clients wishing to abort computation in response to an
530532
/// allocation error are encouraged to call the [`oom`] function,
531533
/// rather than directly invoking `panic!` or similar.
534+
///
535+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
532536
#[stable(feature = "global_alloc", since = "1.28.0")]
533537
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
534538
let size = layout.size();
@@ -587,6 +591,8 @@ pub unsafe trait GlobalAlloc {
587591
/// Clients wishing to abort computation in response to a
588592
/// reallocation error are encouraged to call the [`oom`] function,
589593
/// rather than directly invoking `panic!` or similar.
594+
///
595+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
590596
#[stable(feature = "global_alloc", since = "1.28.0")]
591597
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
592598
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
@@ -727,8 +733,10 @@ pub unsafe trait Alloc {
727733
/// library that aborts on memory exhaustion.)
728734
///
729735
/// Clients wishing to abort computation in response to an
730-
/// allocation error are encouraged to call the `oom` function,
736+
/// allocation error are encouraged to call the [`oom`] function,
731737
/// rather than directly invoking `panic!` or similar.
738+
///
739+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
732740
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr>;
733741

734742
/// Deallocate the memory referenced by `ptr`.
@@ -837,6 +845,8 @@ pub unsafe trait Alloc {
837845
/// Clients wishing to abort computation in response to a
838846
/// reallocation error are encouraged to call the [`oom`] function,
839847
/// rather than directly invoking `panic!` or similar.
848+
///
849+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
840850
unsafe fn realloc(&mut self,
841851
ptr: NonNull<u8>,
842852
layout: Layout,
@@ -881,6 +891,8 @@ pub unsafe trait Alloc {
881891
/// Clients wishing to abort computation in response to an
882892
/// allocation error are encouraged to call the [`oom`] function,
883893
/// rather than directly invoking `panic!` or similar.
894+
///
895+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
884896
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
885897
let size = layout.size();
886898
let p = self.alloc(layout);
@@ -907,6 +919,8 @@ pub unsafe trait Alloc {
907919
/// Clients wishing to abort computation in response to an
908920
/// allocation error are encouraged to call the [`oom`] function,
909921
/// rather than directly invoking `panic!` or similar.
922+
///
923+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
910924
unsafe fn alloc_excess(&mut self, layout: Layout) -> Result<Excess, AllocErr> {
911925
let usable_size = self.usable_size(&layout);
912926
self.alloc(layout).map(|p| Excess(p, usable_size.1))
@@ -929,6 +943,8 @@ pub unsafe trait Alloc {
929943
/// Clients wishing to abort computation in response to a
930944
/// reallocation error are encouraged to call the [`oom`] function,
931945
/// rather than directly invoking `panic!` or similar.
946+
///
947+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
932948
unsafe fn realloc_excess(&mut self,
933949
ptr: NonNull<u8>,
934950
layout: Layout,
@@ -1076,6 +1092,8 @@ pub unsafe trait Alloc {
10761092
/// Clients wishing to abort computation in response to an
10771093
/// allocation error are encouraged to call the [`oom`] function,
10781094
/// rather than directly invoking `panic!` or similar.
1095+
///
1096+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
10791097
fn alloc_one<T>(&mut self) -> Result<NonNull<T>, AllocErr>
10801098
where Self: Sized
10811099
{
@@ -1143,6 +1161,8 @@ pub unsafe trait Alloc {
11431161
/// Clients wishing to abort computation in response to an
11441162
/// allocation error are encouraged to call the [`oom`] function,
11451163
/// rather than directly invoking `panic!` or similar.
1164+
///
1165+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
11461166
fn alloc_array<T>(&mut self, n: usize) -> Result<NonNull<T>, AllocErr>
11471167
where Self: Sized
11481168
{
@@ -1188,6 +1208,8 @@ pub unsafe trait Alloc {
11881208
/// Clients wishing to abort computation in response to a
11891209
/// reallocation error are encouraged to call the [`oom`] function,
11901210
/// rather than directly invoking `panic!` or similar.
1211+
///
1212+
/// [`oom`]: ../../alloc/alloc/fn.oom.html
11911213
unsafe fn realloc_array<T>(&mut self,
11921214
ptr: NonNull<T>,
11931215
n_old: usize,

0 commit comments

Comments
 (0)