Skip to content

Tracking issue for const slice::from_raw_parts_mut (const_slice_from_raw_parts_mut) #67456

Description

@DutchGhost

Make slice::from_raw_parts and slice::from_raw_parts_mut a const fn available under a feature flag.
This would require a change in the ptr module as well, as slice module just forwards to it.

slice::from_raw_parts[mut] is used in alot of places (e.g slice::from_ref[mut], which would get one step closer into constification if slice::from_raw_parts[mut] is a const fn.

Here is a little playground to show it's possible:
https://play.rust-lang.org/?version=nightly&mode=release&edition=2018&gist=dd5c506a3e082c619f557d972e9956ff

In order to get this working, the following functions and functionalities need to be constified:


Implementation PR for ptr::slice_from_raw_parts: #67462


Partially stabilized in #97522; remaining unstable functions:

// core::ptr
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T];

// core::slice
pub const unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T];

// core::ptr::NonNull
pub const fn slice_from_raw_parts(data: NonNull<T>, len: usize) -> Self

Activity

  1. added a commit that references this issue on Dec 21, 2019
  2. added
    T-langRelevant to the language team
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on Dec 21, 2019
  3. added a commit that references this issue on Dec 21, 2019
  4. changed the title [-]feature request: const slice::from_raw_parts[/-] [+]Tracking issue for const slice::from_raw_parts[/+] on Jan 21, 2020
  5. DoumanAsh commented on Apr 22, 2020

    @DoumanAsh

    Is there particular reason why it remains gated by feature flag instead of just being const fn as it is?

  6. DutchGhost commented on Apr 23, 2020

    @DutchGhost
    Author

    Is there particular reason why it remains gated by feature flag instead of just being const fn as it is?

    The constant versions of function's and methods in libcore/libstd need a period of time under a feature flag before they can be stabilized as a const function/method. Const functions are 'relatively' new, and the ability of what one can do inside isn't fully determined yet I think.
    One of those abilities is how to handle raw pointers, which slice::from_raw_parts[mut] needs.

  7. josephlr commented on Apr 24, 2020

    @josephlr
    Contributor

    @DutchGhost would it make sense for the slice::{from_raw_parts[_mut], from_ref, from_mut} to be constified behind this feature as well? The only thing that seems blocking that is this debug_assert which calls is_aligned_and_not_null.

    Checking the alignment will need support from the MIR interpreter, see #62420

  8. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    Libs-SmallLibs issues that are considered "small" or self-contained
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Jul 29, 2020
  9. 32 remaining items

  10. removed
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    on Sep 24, 2024
  11. rfcbot commented on Sep 24, 2024

    @rfcbot

    🔔 This is now entering its final comment period, as per the review above. 🔔

  12. BurntSushi commented on Sep 24, 2024

    @BurntSushi
    Member

    Weird. My box was ticked, but FCP didn't get triggered. I unticked and re-ticked my box.

  13. changed the title [-]Tracking issue for const slice::from_raw_parts[/-] [+]Tracking issue for const slice::from_raw_parts_mut (const_slice_from_raw_parts_mut)[/+] on Sep 24, 2024
  14. added
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Oct 4, 2024
  15. 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.

  16. added 2 commits that reference this issue on Oct 4, 2024
  17. added a commit that references this issue on Oct 4, 2024
  18. added a commit that references this issue on Oct 5, 2024
  19. added a commit that references this issue on Oct 5, 2024
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-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-raw-pointersArea: raw pointers, MaybeUninit, NonNullA-sliceArea: `[T]`B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedT-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