Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,11 @@ use crate::vec::{self, Vec};
/// You can look at these with the [`as_ptr`], [`len`], and [`capacity`]
/// methods:
///
// FIXME Update this when vec_into_raw_parts is stabilized
/// ```
/// use std::mem;
///
/// let story = String::from("Once upon a time...");
///
/// // Prevent automatically dropping the String's data
/// let mut story = mem::ManuallyDrop::new(story);
///
/// let ptr = story.as_mut_ptr();
/// let len = story.len();
/// let capacity = story.capacity();
/// // Deconstruct the String into parts.
/// let (ptr, len, capacity) = story.into_raw_parts();
///
/// // story has nineteen bytes
/// assert_eq!(19, len);
Expand Down Expand Up @@ -932,7 +925,6 @@ impl String {
/// # Examples
///
/// ```
/// #![feature(vec_into_raw_parts)]
/// let s = String::from("hello");
///
/// let (ptr, len, cap) = s.into_raw_parts();
Expand All @@ -941,7 +933,7 @@ impl String {
/// assert_eq!(rebuilt, "hello");
/// ```
#[must_use = "losing the pointer will leak memory"]
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
#[stable(feature = "vec_into_raw_parts", since = "CURRENT_RUSTC_VERSION")]
pub fn into_raw_parts(self) -> (*mut u8, usize, usize) {
self.vec.into_raw_parts()
}
Expand Down Expand Up @@ -970,19 +962,12 @@ impl String {
///
/// # Examples
///
// FIXME Update this when vec_into_raw_parts is stabilized
/// ```
/// use std::mem;
///
/// unsafe {
/// let s = String::from("hello");
///
/// // Prevent automatically dropping the String's data
/// let mut s = mem::ManuallyDrop::new(s);
///
/// let ptr = s.as_mut_ptr();
/// let len = s.len();
/// let capacity = s.capacity();
/// // Deconstruct the String into parts.
/// let (ptr, len, capacity) = s.into_raw_parts();
///
/// let s = String::from_raw_parts(ptr, len, capacity);
///
Expand Down
66 changes: 12 additions & 54 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,21 +592,13 @@ impl<T> Vec<T> {
///
/// # Examples
///
// FIXME Update this when vec_into_raw_parts is stabilized
/// ```
/// use std::ptr;
/// use std::mem;
///
/// let v = vec![1, 2, 3];
///
/// // Prevent running `v`'s destructor so we are in complete control
/// // of the allocation.
/// let mut v = mem::ManuallyDrop::new(v);
///
/// // Pull out the various important pieces of information about `v`
/// let p = v.as_mut_ptr();
/// let len = v.len();
/// let cap = v.capacity();
/// // Deconstruct the vector into parts.
/// let (p, len, cap) = v.into_raw_parts();
///
/// unsafe {
/// // Overwrite memory with 4, 5, 6
Expand Down Expand Up @@ -700,23 +692,13 @@ impl<T> Vec<T> {
///
/// # Examples
///
// FIXME Update this when vec_into_raw_parts is stabilized
/// ```
/// #![feature(box_vec_non_null)]
///
/// use std::ptr::NonNull;
/// use std::mem;
///
/// let v = vec![1, 2, 3];
///
/// // Prevent running `v`'s destructor so we are in complete control
/// // of the allocation.
/// let mut v = mem::ManuallyDrop::new(v);
///
/// // Pull out the various important pieces of information about `v`
/// let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) };
/// let len = v.len();
/// let cap = v.capacity();
/// // Deconstruct the vector into parts.
/// let (p, len, cap) = v.into_parts();
///
/// unsafe {
/// // Overwrite memory with 4, 5, 6
Expand Down Expand Up @@ -783,7 +765,6 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// #![feature(vec_into_raw_parts)]
/// let v: Vec<i32> = vec![-1, 0, 1];
///
/// let (ptr, len, cap) = v.into_raw_parts();
Expand All @@ -798,7 +779,7 @@ impl<T> Vec<T> {
/// assert_eq!(rebuilt, [4294967295, 0, 1]);
/// ```
#[must_use = "losing the pointer will leak memory"]
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
#[stable(feature = "vec_into_raw_parts", since = "CURRENT_RUSTC_VERSION")]
pub fn into_raw_parts(self) -> (*mut T, usize, usize) {
let mut me = ManuallyDrop::new(self);
(me.as_mut_ptr(), me.len(), me.capacity())
Expand All @@ -823,7 +804,7 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// #![feature(vec_into_raw_parts, box_vec_non_null)]
/// #![feature(box_vec_non_null)]
///
/// let v: Vec<i32> = vec![-1, 0, 1];
///
Expand All @@ -840,7 +821,6 @@ impl<T> Vec<T> {
/// ```
#[must_use = "losing the pointer will leak memory"]
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
pub fn into_parts(self) -> (NonNull<T>, usize, usize) {
let (ptr, len, capacity) = self.into_raw_parts();
// SAFETY: A `Vec` always has a non-null pointer.
Expand Down Expand Up @@ -996,29 +976,20 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// # Examples
///
// FIXME Update this when vec_into_raw_parts is stabilized
/// ```
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
/// use std::ptr;
/// use std::mem;
///
/// let mut v = Vec::with_capacity_in(3, System);
/// v.push(1);
/// v.push(2);
/// v.push(3);
///
/// // Prevent running `v`'s destructor so we are in complete control
/// // of the allocation.
/// let mut v = mem::ManuallyDrop::new(v);
///
/// // Pull out the various important pieces of information about `v`
/// let p = v.as_mut_ptr();
/// let len = v.len();
/// let cap = v.capacity();
/// let alloc = v.allocator();
/// // Deconstruct the vector into parts.
/// let (p, len, cap, alloc) = v.into_raw_parts_with_alloc();
///
/// unsafe {
/// // Overwrite memory with 4, 5, 6
Expand Down Expand Up @@ -1116,29 +1087,18 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// # Examples
///
// FIXME Update this when vec_into_raw_parts is stabilized
/// ```
/// #![feature(allocator_api, box_vec_non_null)]
///
/// use std::alloc::System;
///
/// use std::ptr::NonNull;
/// use std::mem;
///
/// let mut v = Vec::with_capacity_in(3, System);
/// v.push(1);
/// v.push(2);
/// v.push(3);
///
/// // Prevent running `v`'s destructor so we are in complete control
/// // of the allocation.
/// let mut v = mem::ManuallyDrop::new(v);
///
/// // Pull out the various important pieces of information about `v`
/// let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) };
/// let len = v.len();
/// let cap = v.capacity();
/// let alloc = v.allocator();
/// // Deconstruct the vector into parts.
/// let (p, len, cap, alloc) = v.into_parts_with_alloc();
///
/// unsafe {
/// // Overwrite memory with 4, 5, 6
Expand Down Expand Up @@ -1206,7 +1166,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, vec_into_raw_parts)]
/// #![feature(allocator_api)]
///
/// use std::alloc::System;
///
Expand All @@ -1228,7 +1188,6 @@ impl<T, A: Allocator> Vec<T, A> {
/// ```
#[must_use = "losing the pointer will leak memory"]
#[unstable(feature = "allocator_api", issue = "32838")]
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
pub fn into_raw_parts_with_alloc(self) -> (*mut T, usize, usize, A) {
let mut me = ManuallyDrop::new(self);
let len = me.len();
Expand Down Expand Up @@ -1256,7 +1215,7 @@ impl<T, A: Allocator> Vec<T, A> {
/// # Examples
///
/// ```
/// #![feature(allocator_api, vec_into_raw_parts, box_vec_non_null)]
/// #![feature(allocator_api, box_vec_non_null)]
///
/// use std::alloc::System;
///
Expand All @@ -1279,7 +1238,6 @@ impl<T, A: Allocator> Vec<T, A> {
#[must_use = "losing the pointer will leak memory"]
#[unstable(feature = "allocator_api", issue = "32838")]
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
pub fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) {
let (ptr, len, capacity, alloc) = self.into_raw_parts_with_alloc();
// SAFETY: A `Vec` always has a non-null pointer.
Expand Down
8 changes: 2 additions & 6 deletions library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,9 @@ pub const fn forget<T: ?Sized>(_: T);
/// // in terms of converting the original inner type (`&i32`) to the new one (`Option<&i32>`),
/// // this has all the same caveats. Besides the information provided above, also consult the
/// // [`from_raw_parts`] documentation.
/// let (ptr, len, capacity) = v_clone.into_raw_parts();
/// let v_from_raw = unsafe {
// FIXME Update this when vec_into_raw_parts is stabilized
/// // Ensure the original vector is not dropped.
/// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
/// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
/// v_clone.len(),
/// v_clone.capacity())
/// Vec::from_raw_parts(ptr.cast::<*mut Option<&i32>>(), len, capacity)
/// };
/// ```
///
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@
#![feature(try_reserve_kind)]
#![feature(try_with_capacity)]
#![feature(unique_rc_arc)]
#![feature(vec_into_raw_parts)]
#![feature(wtf8_internals)]
// tidy-alphabetical-end
//
Expand Down
Loading