Skip to content

Both the name of and the docs for MaybeUninit::uninit_array() make what it actually does somewhat unclear #66845

Closed

Description

@slightlyoutofphase

Basically, based on the name of the function, and also the part of the docs for it that says:

Create a new array of MaybeUninit<T> items, in an uninitialized state.

I initially had the impression that it internally amounted to:

MaybeUninit::<[MaybeUninit<T>; LEN]>::uninit()

and returned an uninitialized array of uninitialized MaybeUninits.

However, after looking at the source, I realized it actually amounts to:

MaybeUninit::<[MaybeUninit<T>; LEN]>::uninit().assume_init()

and returns an initialized array of uninitialized MaybeUninits (which is what I actually needed, so that's good at least!)

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    T-libs-api[DEPRECATED; DO NOT USE]
    on Nov 28, 2019
  2. hkBst commented on Feb 7, 2025

    @hkBst
    Member

    IIUC you assumed MaybeUninit<[MaybeUninit<T>; N]> as output, but the documented output is [MaybeUninit<T>; N]. I don't think MaybeUninit<[MaybeUninit<T>; N]> is a useful type as an array really is nothing more than its elements, so if those are uninitialized, then the array is already uninitialized as a whole, since there is nothing else besides the elements.

    Maybe the "in an uninitialized state" is ambiguous as to whether it refers to the array or the elements though.

  3. RalfJung commented on Feb 21, 2025

    @RalfJung
    Member

    However, after looking at the source,

    You don't have to look at the source for that, the type is right there in the docs. :)

  4. added a commit that references this issue on Feb 21, 2025
  5. added 2 commits that reference this issue on Feb 26, 2025
    72d0a9e
    bcfff3d
  6. added a commit that references this issue on Feb 26, 2025
    1addd61
  7. added 2 commits that reference this issue on Mar 11, 2025
    4a53c0a
    ea50b43
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

    A-arrayArea: `[T; N]`A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions