@@ -55,9 +55,12 @@ use crate::ptr;
5555/// and implementors must ensure such contracts remain true.
5656///
5757/// * You may not rely on allocations actually happening, even if there are explicit
58- /// heap allocations in the source. The optimizer may detect allocation/deallocation
59- /// pairs that it can instead move to stack allocations/deallocations and thus never
60- /// invoke the allocator here.
58+ /// heap allocations in the source.
59+ /// The optimizer may detect unused allocations that it can either
60+ /// eliminate entirely or move to the stack and thus never invoke the allocator here. The
61+ /// optimizer may further assume that allocation is infallible, so code that used to fail due
62+ /// to allocator failures may now suddenly work because the optimizer worked around the
63+ /// need for an allocation.
6164/// More concretely, the following code example is unsound, irrespective of whether your
6265/// custom allocator allows counting how many allocations have happened.
6366///
@@ -67,10 +70,10 @@ use crate::ptr;
6770/// unsafe { std::intrinsics::assume(number_of_heap_allocs > 0); }
6871/// ```
6972///
70- /// Note that allocation/deallocation pairs being moved to the stack is not the only
73+ /// Note that the optimizations mentioned above are not the only
7174/// optimization that can be applied. You may generally not rely on heap allocations
72- /// happening, if they can be removed without changing program behaviour .
73- /// Whether allocations happen or not is not part of the program behaviour , even if it
75+ /// happening if they can be removed without changing program behavior .
76+ /// Whether allocations happen or not is not part of the program behavior , even if it
7477/// could be detected via an allocator that tracks allocations by printing or otherwise
7578/// having side effects.
7679#[ stable( feature = "global_alloc" , since = "1.28.0" ) ]
0 commit comments