-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
NonNull's as_ref / as_mut don't have arbitrary lifetimes as stated #80183
Copy link
Copy link
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.
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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The docs for
NonNull::as_refmention: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):
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:
as_refas_mutAdditionally, these unstable methods with
# also have the same problem.as_uninit_sliceas_uninit_slice_mutas_uninit_refas_uninit_mut