Safety comment in std::ptr::NonNull::dangling
code was invalidated by a refactoring
#132004
Labels
A-docs
Area: Documentation for any part of the project, including the compiler, standard library, and tools
Libs-Small
Libs issues that are considered "small" or self-contained
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
The implementation of the
std::ptr::NonNull::dangling
function looked like this:until a recent change (b58f647) made it into this:
The code has changed, but the comment has not, and is now unrelated to the code.
Furthermore, it is unclear how to rewrite this comment correctly. The documentation of
std::ptr::dangling_mut
function only guarantees that it “Creates a new pointer that is dangling, but well-aligned”. However, the documentation ofstd::ptr
module defines a dangling pointer with “We say that a pointer is "dangling" if it is not valid for any non-zero-sized accesses. This means out-of-bounds pointers, pointers to freed memory, null pointers, and pointers created withNonNull::dangling
are all dangling”. Since a dangling pointer can technically be null, the fact thatstd::ptr::dangling_mut
returns a non-null pointer is an undocumented behaviour. This means that the safety ofstd::ptr::NonNull::dangling
hinges on an undocumented behavior of another function.The text was updated successfully, but these errors were encountered: