-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullT-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullT-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.