reference NonNull::dangling

This commit is contained in:
Ralf Jung
2020-11-20 10:25:59 +01:00
parent 0f572a9810
commit a7677f7714
2 changed files with 12 additions and 9 deletions

View File

@@ -20,11 +20,12 @@
//! be *dereferenceable*: the memory range of the given size starting at the pointer must all be
//! within the bounds of a single allocated object. Note that in Rust,
//! every (stack-allocated) variable is considered a separate allocated object.
//! * Even for operations of [size zero][zst], the pointer must not be "dangling" in the sense of
//! pointing to deallocated memory. However, casting any non-zero integer literal to a pointer is
//! valid for zero-sized accesses. This corresponds to writing your own allocator; allocating
//! zero-sized objects is not very hard. In contrast, when you use the standard allocator, after
//! memory got deallocated, even zero-sized accesses to that memory are invalid.
//! * Even for operations of [size zero][zst], the pointer must not be pointing to deallocated
//! memory, i.e., deallocation makes pointers invalid even for zero-sized operations. However,
//! casting any non-zero integer *literal* to a pointer is valid for zero-sized accesses, even if
//! some memory happens to exist at that address and gets deallocated. This corresponds to writing
//! your own allocator: allocating zero-sized objects is not very hard. The canonical way to
//! obtain a pointer that is valid for zero-sized accesses is [`NonNull::dangling`].
//! * All accesses performed by functions in this module are *non-atomic* in the sense
//! of [atomic operations] used to synchronize between threads. This means it is
//! undefined behavior to perform two concurrent accesses to the same location from different