Skip to content

Tracking Issue for const_maybe_uninit_assume_init #86722

Closed

Description

@usbalbin

Feature gate: #![feature(const_maybe_uninit_assume_init)]

This is a tracking issue for turning the methods assume_init, assume_init_ref, assume_init_mut, slice_assume_init_ref, slice_assume_init_mut of MaybeUninit into const fns. Note that the implementation of the latter two slice related methods are currently behind maybe_uninit_slice #63569, while the constness is behind const_maybe_uninit_assume_init.

Public API

impl<T> MaybeUninit<T> {
    pub const unsafe fn assume_init(self) -> T;
    pub const unsafe fn assume_init_ref(&self) -> &T;
    pub const unsafe fn assume_init_mut(&mut self) -> &mut T;
}

// These function impls are behind `maybe_uninit_slice` while the constnes is `const_maybe_uninit_assume_init` (this issue)
impl<T> MaybeUninit<T> {
    pub const unsafe fn slice_assume_init_ref(slice: &[Self]) -> &[T];
    pub const unsafe fn slice_assume_init_mut(slice: &mut [Self]) -> &mut [T];
}

Steps / History

Unresolved Questions

  • None yet.

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Jun 29, 2021
  2. jhpratt commented on Sep 28, 2021

    @jhpratt
    Member

    @RalfJung @oli-obk there should be no issues stabilizing this, correct? I'm going through some things that can be stabilized as const and this seems like it would fall logically from the const union PR that has already been merged.

    I was planning to stabilize assume_init and assume_init_ref, as assume_init_mut would be blocked on const mut refs with the two slice methods being unstable in general (the immutable one could have its rustc_const_unstable annotation removed, though).

  3. oli-obk commented on Sep 28, 2021

    @oli-obk
    Contributor

    we haven't stabilized transmute yet, all that is blocked on me finishing https://github.com/rust-lang/nomicon/pull/221, then we can start the stabilization wave for unsafe const stuff

  4. jhpratt commented on Sep 28, 2021

    @jhpratt
    Member

    Was that not rust-lang/rust#85769?

  5. oli-obk commented on Sep 28, 2021

    @oli-obk
    Contributor

    🤦 I am completely lost at the moment on what is stabilized and what is not... I really need to update the skill tree...

    Yea, those are trivial to replicate in bad ways on stable then... so we should stabilize them

  6. jhpratt commented on Sep 29, 2021

    @jhpratt
    Member

    It looks like a number of methods rely on dereferencing a raw pointer or reading one, all of which we don't want at compile-time for the time being due to some uncertainty, correct? If this is permissible, just say so and I can include them.

    The one method that can clearly be stabilized without issue is assume_init (with array_assume_init being able to be stabilized with the method itself).

  7. oli-obk commented on Sep 29, 2021

    @oli-obk
    Contributor

    We should stabilize raw pointer deref, otherwise ppl will start transmuting raw pointers to references and dereferencing those

  8. jhpratt commented on Sep 29, 2021

    @jhpratt
    Member

    Just sent Ralf a PM on Zulip asking him to check this out. I recall him having an objection to something of the sort when stabilizing const transmutes — I believe we initially wanted a lint.

  9. RalfJung commented on Sep 30, 2021

    @RalfJung
    Member

    Yeah there was the idea of having a lint against ptr-to-int transmutes.

    My only concern with raw pointers is how and where to document that type-punning loads (i.e., raw-ptr-based transmutes) of pointers to integers are considered UB during CTFE.

  10. jhpratt commented on Sep 30, 2021

    @jhpratt
    Member

    So raw pointer deref could be stabilized, correct? Dereferencing raw pointers is unsafe to begin with, so documenting that shouldn't be an issue.

  11. RalfJung commented on Sep 30, 2021

    @RalfJung
    Member

    so documenting that shouldn't be an issue.

    Where would you put that documentation though? And would anyone actually read it?^^

    But, yeah, just from an implementation perspective I can't think of any reason how raw ptr deref could screw us now that we have stabilized transmutes and union field accesses.

  12. jhpratt commented on Sep 30, 2021

    @jhpratt
    Member

    I removed bit of my comment that because I realized it was orthogonal to this issue. Sounds good though 👍

  13. sugar700 commented on Nov 22, 2021

    @sugar700
    Contributor

    Is there anything blocking stabilization of const MaybeUninit::assume_init and const MaybeUninit::assume_init_ref at this point?

  14. jhpratt commented on Nov 22, 2021

    @jhpratt
    Member

    It's in FCP right now!

  15. 13 remaining items

  16. rfcbot commented on Oct 4, 2024

    @rfcbot

    The final comment period, with a disposition to merge, as per the review above, is now complete.

    As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

    This will be merged soon.

  17. RalfJung commented on Oct 4, 2024

    @RalfJung
    Member

    @workingjubilee is there a reason this is not part of your big const stabilization PR?
    It doesn't seem to have an open PR at all right now.

  18. workingjubilee commented on Oct 5, 2024

    @workingjubilee
    Member

    @RalfJung No reason, I think! Slipped through the cracks because I am merely mortal.

  19. workingjubilee commented on Oct 5, 2024

    @workingjubilee
    Member

    Oh, I think I missed this because I looked for features, when stabilizing things, with actual issue numbers in the code... this thing had never gotten its correct issue number assigned in the code.

  20. RalfJung commented on Oct 5, 2024

    @RalfJung
    Member

    Oh lol this had issue = "none"? I guess someone forgot to note down the tracking issue.^^

    Thanks for making a PR!

  21. added 2 commits that reference this issue on Oct 13, 2024
  22. added a commit that references this issue on Oct 14, 2024
  23. added a commit that references this issue on Dec 2, 2024
  24. added a commit that references this issue on Dec 3, 2024
  25. added a commit that references this issue on Mar 11, 2025
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 RFCT-libs-api[DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions