Skip to content

Tracking Issue for pointer methods returning MaybeUninit<T> #75402

Open

Description

@TimDiekmann

This is a tracking issue for methods on pointer types returning MaybeUninit: as_uninit_ref/mut and as_uninit_slice(_mut) on mutable and const raw pointers and NonNull.
The feature gate for the issue is #![feature(ptr_as_uninit)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

Implementation history

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Aug 11, 2020
  2. RalfJung commented on Aug 17, 2020

    @RalfJung
    Member

    A possible concern for stabilization is that these methods will be somewhat redundant if we end up deciding that references do not have to point to valid data -- though maybe reflecting the initialization state is a good idea even in that case? Also it seems likely that some T will not allow uninitialized references, i.e., there is demand for making &! uninhabited.

  3. added a commit that references this issue on Aug 18, 2020
  4. Kixunil commented on Feb 4, 2022

    @Kixunil
    Contributor

    Having such cast on pointers rather than references could be useful in situations like in #93653 (although having cast on Box is even better in that case).

    @RalfJung any good resource explaining why it'd be useful to allow uninitialized references? Anyway, I do like tracking (un)initializedness in type even for documentation value.

  5. RalfJung commented on Feb 4, 2022

    @RalfJung
    Member

    For documentation, it is the safety invariant of a type that is most relevant, and those certainly still apply recursively below references.

    For the validity invariant, see rust-lang/unsafe-code-guidelines#77 for the discussion. Basically, specifying the language becomes a hell of a lot simpler if the validity invariant depends solely on the bit pattern of the value itself, and not on other state of the system such as the current contents of memory. I would argue that directly translates to making life easier for unsafe code authors (as one of the consumers of such a specification). Also generally I think we should require reasons to make something UB, the default should be not-UB. :)

  6. Raekye commented on Apr 16, 2022

    @Raekye
    Contributor

    I noticed that as_uninit_* on pointers take self by value (and pointers are Copy), e.g. see as_uninit_mut.

    However, on NonNull, these functions take self by reference, e.g. see the function with the same name by for NonNull: as_uninit_mut takes self by mutable reference. Even more inconsistent, as_uninit_slice_mut returns a mutable reference, but takes self by immutable reference.

    I think these methods should take self by value for consistency. The returned lifetime is unbounded anyways and not tied to the pointer/NonNull value anyways

  7. RalfJung commented on Apr 16, 2022

    @RalfJung
    Member

    NonNull::as_ref takes &self. It would seem odd for NonNull::as_uninit_ref to diverge from that?

  8. added a commit that references this issue on May 23, 2022
  9. pnkfelix commented on Sep 23, 2022

    @pnkfelix
    Contributor

    Visiting for T-compiler backlog bonanza

    @RalfJung 's comments above were somewhat echo'ed by @m-ou-se in the meeting

    @rustbot label: S-tracking-design-concerns

  10. added 2 commits that reference this issue on Sep 10, 2024
  11. added a commit that references this issue on Sep 10, 2024
  12. added 2 commits that reference this issue on Jul 13, 2026
  13. added a commit that references this issue on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-design-concernsStatus: There are blocking design concerns.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions