diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2023-12-12 19:55:43 +0000 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2024-02-12 14:02:30 +0000 |
| commit | fb5ed2986e7d999d57e907f2c3351a1b3dac59c3 (patch) | |
| tree | 2b79473dc85dd343b3157433b12cb5fe8611cc30 /library/core/src/alloc | |
| parent | b17491c8f6d555386104dfd82004c01bfef09c95 (diff) | |
| download | rust-fb5ed2986e7d999d57e907f2c3351a1b3dac59c3.tar.gz rust-fb5ed2986e7d999d57e907f2c3351a1b3dac59c3.zip | |
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 {}
```
Diffstat (limited to 'library/core/src/alloc')
| -rw-r--r-- | library/core/src/alloc/mod.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/library/core/src/alloc/mod.rs b/library/core/src/alloc/mod.rs index 78091c01729..681d617af93 100644 --- a/library/core/src/alloc/mod.rs +++ b/library/core/src/alloc/mod.rs @@ -95,8 +95,10 @@ impl fmt::Display for AllocError { /// # Safety /// /// * Memory blocks returned from an allocator that are [*currently allocated*] must point to -/// valid memory and retain their validity while they are [*currently allocated*] and at -/// least one of the instance and all of its clones has not been dropped. +/// valid memory and retain their validity while they are [*currently allocated*] and the shorter +/// of: +/// - the borrow-checker lifetime of the allocator type itself. +/// - as long as at least one of the instance and all of its clones has not been dropped. /// /// * copying, cloning, or moving the allocator must not invalidate memory blocks returned from this /// allocator. A copied or cloned allocator must behave like the same allocator, and |
