Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arielb1 opened this issue Oct 3, 2016 · 7 comments · Fixed by #68234
Closed

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

arielb1 opened this issue Oct 3, 2016 · 7 comments · Fixed by #68234
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@arielb1
Copy link
Contributor

arielb1 commented Oct 3, 2016

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.

@arielb1 arielb1 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Oct 3, 2016
@Thiez
Copy link
Contributor

Thiez commented Oct 3, 2016

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

@durka
Copy link
Contributor

durka commented Oct 3, 2016

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?

@arielb1
Copy link
Contributor Author

arielb1 commented Oct 3, 2016

@durka

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

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@oli-obk oli-obk added C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed C-bug Category: This is a bug. labels May 8, 2019
Centril added a commit to Centril/rust that referenced this issue Jun 19, 2019
 Add functions for building raw slices to libcore

implement rust-lang#36925
Centril added a commit to Centril/rust that referenced this issue Jun 19, 2019
 Add functions for building raw slices to libcore

implement rust-lang#36925
@CAD97
Copy link
Contributor

CAD97 commented Jan 13, 2020

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)).

@nikomatsakis
Copy link
Contributor

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

@SimonSapin
Copy link
Contributor

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

@SimonSapin SimonSapin added B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Jan 15, 2020
@SimonSapin SimonSapin 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] Jan 15, 2020
@SimonSapin
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants