Skip to content

Tracking Issue for const_ptr_read #80377

Closed
@usbalbin

Description

@usbalbin

Feature gate: #![feature(const_ptr_read)]

This is a tracking issue for making the functions ptr::read and ptr::read_unaligned, and the same methods on *const T and *mut T, const fn. This unlocks things like moving values out of arrays in const context.

Public API

mod ptr {
    pub const unsafe fn read<T>(src: *const T) -> T;
    pub const unsafe fn read_unaligned<T>(src: *const T) -> T;
}

impl<T> *const T {
    pub const unsafe fn read(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
}

impl<T> *mut T {
    pub const unsafe fn read(self) -> T;
    pub const unsafe fn read_unaligned(self) -> T;
}

Steps / History

Related

Unresolved Questions

Inorder to make intrinsics::copy and intrinsics::copy_nonoverlapping compile as const fn, some checks were removed.
See comment for some more info

For this PR, I see two options:

  • Leave it as "something we can do once we have a story for const-dependent dispatch".
  • Comment out the debug assertions for now. Their usefulness is anyway limited since the libstd everyone uses is compiled without debug assertions.

I guess the question is one of evaluating the relative usefulness of these new const operations vs the assertions.

(#79684 did the Comment out the debug assertions for now.-thing).

So the question is, how do we bring them back?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-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

    No branches or pull requests

    Issue actions