Skip to content

Commit fb5ed29

Browse files
committed
Clarify the lifetimes of allocations returned by the Allocator trait
The previous definition (accidentally) disallowed the implementation of stack-based allocators whose memory would become invalid once the lifetime of the allocator type ended. This also ensures the validity of the following blanket implementation: ```rust impl<A: Allocator> Allocator for &'_ A {} ```
1 parent b17491c commit fb5ed29

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/core/src/alloc/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ impl fmt::Display for AllocError {
9595
/// # Safety
9696
///
9797
/// * Memory blocks returned from an allocator that are [*currently allocated*] must point to
98-
/// valid memory and retain their validity while they are [*currently allocated*] and at
99-
/// least one of the instance and all of its clones has not been dropped.
98+
/// valid memory and retain their validity while they are [*currently allocated*] and the shorter
99+
/// of:
100+
/// - the borrow-checker lifetime of the allocator type itself.
101+
/// - as long as at least one of the instance and all of its clones has not been dropped.
100102
///
101103
/// * copying, cloning, or moving the allocator must not invalidate memory blocks returned from this
102104
/// allocator. A copied or cloned allocator must behave like the same allocator, and

0 commit comments

Comments
 (0)