Skip to content

Commit

Permalink
Auto merge of #68234 - CAD97:slice-from-raw-parts, r=KodrAus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jan 28, 2020
2 parents 67fae22 + 1c0d485 commit 8201866
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
#![feature(ptr_offset_from)]
#![feature(rustc_attrs)]
#![feature(receiver_trait)]
#![feature(slice_from_raw_parts)]
#![feature(specialization)]
#![feature(staged_api)]
#![feature(std_internals)]
Expand Down
11 changes: 5 additions & 6 deletions src/libcore/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,16 @@ pub(crate) struct FatPtr<T> {
/// # Examples
///
/// ```rust
/// #![feature(slice_from_raw_parts)]
/// use std::ptr;
///
/// // create a slice pointer when starting out with a pointer to the first element
/// let mut x = [5, 6, 7];
/// let ptr = &mut x[0] as *mut _;
/// let slice = ptr::slice_from_raw_parts_mut(ptr, 3);
/// let x = [5, 6, 7];
/// let ptr = x.as_ptr();
/// let slice = ptr::slice_from_raw_parts(ptr, 3);
/// assert_eq!(unsafe { &*slice }[2], 7);
/// ```
#[inline]
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
#[stable(feature = "slice_from_raw_parts", since = "1.42.0")]
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
unsafe { Repr { raw: FatPtr { data, len } }.rust }
Expand All @@ -265,7 +264,7 @@ pub const fn slice_from_raw_parts<T>(data: *const T, len: usize) -> *const [T] {
/// [`slice_from_raw_parts`]: fn.slice_from_raw_parts.html
/// [`from_raw_parts_mut`]: ../../std/slice/fn.from_raw_parts_mut.html
#[inline]
#[unstable(feature = "slice_from_raw_parts", reason = "recently added", issue = "36925")]
#[stable(feature = "slice_from_raw_parts", since = "1.42.0")]
#[rustc_const_unstable(feature = "const_slice_from_raw_parts", issue = "67456")]
pub const fn slice_from_raw_parts_mut<T>(data: *mut T, len: usize) -> *mut [T] {
unsafe { Repr { raw: FatPtr { data, len } }.rust_mut }
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#![feature(iter_is_partitioned)]
#![feature(iter_order_by)]
#![feature(cmp_min_max_by)]
#![feature(slice_from_raw_parts)]
#![feature(const_slice_from_raw_parts)]
#![feature(const_raw_ptr_deref)]
#![feature(never_type)]
Expand Down

0 comments on commit 8201866

Please sign in to comment.