Uh oh!
There was an error while loading. Please reload this page.
Add functions for building raw slices to libcore - #60667
Conversation
rust-highfive
commented
May 9, 2019
(rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
commented
May 9, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Uh oh!
There was an error while loading. Please reload this page.
petertodd
commented
May 11, 2019
via email
Hmm, I wonder if there's code that would have issues with zero-sized-types and slice lens > isize::MAX? I know I've had that idea as a way to hack in custom DST's; wouldn't surprise me if others did too.
Maybe we do need to say that while it's safe to create such a pointer, it's unsafe to dereference one? …On May 10, 2019 4:24:48 AM EDT, Oliver Scherer ***@***.***> wrote:
oli-obk commented on this pull request.
> +/// Performs the same functionality as [`from_raw_parts`], except
that a
+/// mutable slice is returned.
+///
+/// # Panics
+///
+/// The total size of the slice should be no
+/// larger than `isize::MAX` **bytes** in memory.
+///
+/// See the documentation of [`from_raw_parts`] for more details.
+///
+/// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
+#[inline]
+#[unstable(feature = "slice_from_raw_parts", reason = "recently
added", issue = "36925")]
+pub fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut
[T] {
+ debug_assert!(mem::size_of::<T>().saturating_mul(len) <=
isize::max_value() as usize,
+ "attempt to create slice covering half the address
space");
It's not a safety issue. I mostly thought of it as "you're going into
weird places"-territory. There's basically no reason to ever create
such raw slices. I should remove the `Panics` note though. This is just
a debug assertion that we'd only get on the builders with debug
assertions, so it's mostly a sanity test for our own test suite.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#60667 (comment) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bors
commented
May 28, 2019
☔ The latest upstream changes (presumably #61274) made this pull request unmergeable. Please resolve the merge conflicts. |
Centril
commented
May 29, 2019
r? @sfackler |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sfackler
commented
May 30, 2019
LGTM other than the one nit. |
rust-highfive
commented
Jun 19, 2019
The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
oli-obk
commented
Jun 19, 2019
@bors r=sfackler |
bors
commented
Jun 19, 2019
📌 Commit 8b21b07 has been approved by |
Add functions for building raw slices to libcore implement rust-lang#36925
Add functions for building raw slices to libcore implement rust-lang#36925
SimonSapin
commented
Jan 15, 2020
When landing a PR that adds a |
Stabilize ptr::slice_from_raw_parts[_mut] Closes#36925, the tracking issue. Initial impl: #60667 r? @rust-lang/libs In addition to stabilizing, I've adjusted the example of `ptr::slice_from_raw_parts` to use `slice_from_raw_parts` instead of `slice_from_raw_parts_mut`, which was unnecessary for the example as written.
implement #36925