Skip to content

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

Closed
@DutchGhost

Description

@DutchGhost
Contributor

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

added a commit that references this issue on Dec 21, 2019

Rollup merge of rust-lang#67462 - DutchGhost:const_slice_from_raw_par…

a3cc9b4
added
T-langRelevant to the language team
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
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
added a commit that references this issue on Dec 21, 2019

Rollup merge of rust-lang#67462 - DutchGhost:const_slice_from_raw_par…

f43ced3
changed the title [-]feature request: const slice::from_raw_parts[/-] [+]Tracking issue for const slice::from_raw_parts[/+] on Jan 21, 2020
DoumanAsh

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?

DutchGhost

DutchGhost commented on Apr 23, 2020

@DutchGhost
ContributorAuthor

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.

josephlr

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

added
B-unstableBlocker: Implemented in the nightly compiler and unstable.
Libs-SmallLibs issues that are considered "small" or self-contained
on Jul 29, 2020

58 remaining items

Loading
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 RFCLibs-SmallLibs issues that are considered "small" or self-containedLibs-TrackedLibs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.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

      Participants

      @joshtriplett@tobz@RalfJung@BurntSushi@eduardosm

      Issue actions

        Tracking issue for const slice::from_raw_parts_mut (const_slice_from_raw_parts_mut) · Issue #67456 · rust-lang/rust