Skip to content

Tracking issue for ptr::slice_from_raw_parts[_mut] #36925

Closed

Description

@arielb1

In stable Rust, the only way to get a *const [T] with an arbitrary length is through slice::from_raw_parts. Unfortunately, that function returns a &[T], which makes it very dubious to use with arbitrary raw pointers.

Activity

  1. Thiez commented on Oct 3, 2016

    @Thiez
    Contributor

    Given that Index isn't defined for *const [T], what would be the value of being able to create *const [T]?

  2. durka commented on Oct 3, 2016

    @durka
    Contributor

    Why would you want one, but also, this seems like it depends on (yet to be decided?) details of the memory model. Is the fleeting moment where a reference exists in unsafe { slice::from_raw_parts(0xDEADBEEF, 42) as *const [T] } enough to invoke UB if the pointer is invalid?

  3. arielb1 commented on Oct 3, 2016

    @arielb1
    ContributorAuthor

    @durka

    If the reference is null, then this is insta-UB for sure.

  4. added
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    and removed
    C-bugCategory: This is a bug.
    on May 8, 2019
  5. added 2 commits that reference this issue on Jun 19, 2019
  6. CAD97 commented on Jan 13, 2020

    @CAD97
    Contributor

    Is there anything holding slice_from_raw_parts[_mut] from stabilizing? If not, I'd like to propose stabilization of these functions, as they are rather simple in concept and allow avoiding manifesting references during (slice) pointer manipulation.

    cc @RalfJung #63880 #63851 @rust-lang/wg-unsafe-code-guidelines

    If I'm reading the various issue threads correctly, the validity invariant of pointer metadata is at max that of the metadata type. For slice pointers, the metadata is typed at usize.

    Context: I happen to currently be writing a library that cannot use the reference-based functions, because though the pointers are known to be non-null (and valid), it is not (and cannot be, with the current abstraction) known whether the pointer has unique or shared provenance (thus should use slice::from_raw_parts or slice::from_raw_parts_mut to be sound). (Specifically, I'm now adding the bits required to handle erasing slice types. I can bifurcate my unerase function into unerase_const and unerase_mut, but so far, it works fine with one unerase operating over ptr::NonNull, and it'd be sad to have the _const/_mut split hanging around even after these functions stabilize (assuming they can)).

  7. nikomatsakis commented on Jan 13, 2020

    @nikomatsakis
    Contributor

    I don't recall any reason that slice_from_raw_parts cannot be stabilized.

  8. SimonSapin commented on Jan 15, 2020

    @SimonSapin
    Contributor

    The implementation PR #60667 used this feature requested as a tracking issue, but this wasn’t labelled properly. Doing so now.

  9. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    and removed
    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
    on Jan 15, 2020
  10. changed the title [-]There is no stable way to get an `*const [T]` from a ptr and a len[/-] [+]Tracking issue for `ptr::slice_from_raw_parts[_mut]`[/+] on Jan 15, 2020
  11. SimonSapin commented on Jan 15, 2020

    @SimonSapin
    Contributor

    By the way, rust-lang/rfcs#2580 would also cover this :)

  12. added a commit that references this issue on Jan 28, 2020
    8201866
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

    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-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions