Skip to content

Tracking issue for the cast method of raw pointers #60602

Closed
@SimonSapin

Description

@SimonSapin

#60601 adds:

impl<T: ?Sized> *mut T {
    /// Cast to a pointer to a different type
    #[inline]
    pub const fn cast<U>(self) -> *mut U {
        self as _
    }
}

impl<T: ?Sized> *const T {
    /// Cast to a pointer to a different type
    #[inline]
    pub const fn cast<U>(self) -> *const U {
        self as _
    }
}

Like with NonNull::cast, the input pointed type does not need to be Sized but the output pointed type does, because we wouldn’t know what appropriate pointer metadata (slice length, trait object vtable, …) to insert. The actual requirement is that the pointer is thin, but Sized is the closest approximation we have (until we add something like T: ptr::Pointee<Metadata=()>).

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-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