@@ -55,9 +55,12 @@ use crate::ptr;
55
55
/// and implementors must ensure such contracts remain true.
56
56
///
57
57
/// * 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.
61
64
/// More concretely, the following code example is unsound, irrespective of whether your
62
65
/// custom allocator allows counting how many allocations have happened.
63
66
///
@@ -67,10 +70,10 @@ use crate::ptr;
67
70
/// unsafe { std::intrinsics::assume(number_of_heap_allocs > 0); }
68
71
/// ```
69
72
///
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
71
74
/// 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
74
77
/// could be detected via an allocator that tracks allocations by printing or otherwise
75
78
/// having side effects.
76
79
#[ stable( feature = "global_alloc" , since = "1.28.0" ) ]
0 commit comments