Closed
Description
The docs for NonNull::as_ref
mention:
You must enforce Rust's aliasing rules, since the returned lifetime 'a is arbitrarily chosen and does not necessarily reflect the actual lifetime of the data. [...]
Which makes sense, the pointer doesn't carry a lifetime with it, so we need to decide on it. However, the implementation actually looks like this (with implicit lifetimes shown for clarity):
pub unsafe fn as_ref<'a>(&'a self) -> &'a T {
// ...
}
This makes it so the reference constructed has the same lifetime as the pointer variable, which is likely not what is intended.
The same occurs for all of these methods currently:
Additionally, these unstable methods with #![feature(ptr_as_uninit)]
(#75402) also have the same problem.