Skip to content

Commit 8f5d6c0

Browse files
committed
Stabilize vec_into_raw_parts
1 parent 9312cd6 commit 8f5d6c0

File tree

4 files changed

+19
-69
lines changed

4 files changed

+19
-69
lines changed

library/alloc/src/string.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,13 @@ use crate::vec::{self, Vec};
265265
/// You can look at these with the [`as_ptr`], [`len`], and [`capacity`]
266266
/// methods:
267267
///
268-
// FIXME Update this when vec_into_raw_parts is stabilized
269268
/// ```
270269
/// use std::mem;
271270
///
272271
/// let story = String::from("Once upon a time...");
273272
///
274-
/// // Prevent automatically dropping the String's data
275-
/// let mut story = mem::ManuallyDrop::new(story);
276-
///
277-
/// let ptr = story.as_mut_ptr();
278-
/// let len = story.len();
279-
/// let capacity = story.capacity();
273+
/// // Deconstruct the String into parts.
274+
/// let (ptr, len, capacity) = story.into_raw_parts();
280275
///
281276
/// // story has nineteen bytes
282277
/// assert_eq!(19, len);
@@ -932,7 +927,6 @@ impl String {
932927
/// # Examples
933928
///
934929
/// ```
935-
/// #![feature(vec_into_raw_parts)]
936930
/// let s = String::from("hello");
937931
///
938932
/// let (ptr, len, cap) = s.into_raw_parts();
@@ -941,7 +935,7 @@ impl String {
941935
/// assert_eq!(rebuilt, "hello");
942936
/// ```
943937
#[must_use = "losing the pointer will leak memory"]
944-
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
938+
#[stable(feature = "vec_into_raw_parts", since = "CURRENT_RUSTC_VERSION")]
945939
pub fn into_raw_parts(self) -> (*mut u8, usize, usize) {
946940
self.vec.into_raw_parts()
947941
}
@@ -970,19 +964,14 @@ impl String {
970964
///
971965
/// # Examples
972966
///
973-
// FIXME Update this when vec_into_raw_parts is stabilized
974967
/// ```
975968
/// use std::mem;
976969
///
977970
/// unsafe {
978971
/// let s = String::from("hello");
979972
///
980-
/// // Prevent automatically dropping the String's data
981-
/// let mut s = mem::ManuallyDrop::new(s);
982-
///
983-
/// let ptr = s.as_mut_ptr();
984-
/// let len = s.len();
985-
/// let capacity = s.capacity();
973+
/// // Deconstruct the String into parts.
974+
/// let (ptr, len, capacity) = s.into_raw_parts();
986975
///
987976
/// let s = String::from_raw_parts(ptr, len, capacity);
988977
///

library/alloc/src/vec/mod.rs

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -592,21 +592,14 @@ impl<T> Vec<T> {
592592
///
593593
/// # Examples
594594
///
595-
// FIXME Update this when vec_into_raw_parts is stabilized
596595
/// ```
597596
/// use std::ptr;
598597
/// use std::mem;
599598
///
600599
/// let v = vec![1, 2, 3];
601600
///
602-
/// // Prevent running `v`'s destructor so we are in complete control
603-
/// // of the allocation.
604-
/// let mut v = mem::ManuallyDrop::new(v);
605-
///
606-
/// // Pull out the various important pieces of information about `v`
607-
/// let p = v.as_mut_ptr();
608-
/// let len = v.len();
609-
/// let cap = v.capacity();
601+
/// // Deconstruct the vector into parts.
602+
/// let (p, len, cap) = v.into_raw_parts();
610603
///
611604
/// unsafe {
612605
/// // Overwrite memory with 4, 5, 6
@@ -700,7 +693,6 @@ impl<T> Vec<T> {
700693
///
701694
/// # Examples
702695
///
703-
// FIXME Update this when vec_into_raw_parts is stabilized
704696
/// ```
705697
/// #![feature(box_vec_non_null)]
706698
///
@@ -709,14 +701,8 @@ impl<T> Vec<T> {
709701
///
710702
/// let v = vec![1, 2, 3];
711703
///
712-
/// // Prevent running `v`'s destructor so we are in complete control
713-
/// // of the allocation.
714-
/// let mut v = mem::ManuallyDrop::new(v);
715-
///
716-
/// // Pull out the various important pieces of information about `v`
717-
/// let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) };
718-
/// let len = v.len();
719-
/// let cap = v.capacity();
704+
/// // Deconstruct the vector into parts.
705+
/// let (p, len, cap) = v.into_parts();
720706
///
721707
/// unsafe {
722708
/// // Overwrite memory with 4, 5, 6
@@ -783,7 +769,6 @@ impl<T> Vec<T> {
783769
/// # Examples
784770
///
785771
/// ```
786-
/// #![feature(vec_into_raw_parts)]
787772
/// let v: Vec<i32> = vec![-1, 0, 1];
788773
///
789774
/// let (ptr, len, cap) = v.into_raw_parts();
@@ -798,7 +783,7 @@ impl<T> Vec<T> {
798783
/// assert_eq!(rebuilt, [4294967295, 0, 1]);
799784
/// ```
800785
#[must_use = "losing the pointer will leak memory"]
801-
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
786+
#[stable(feature = "vec_into_raw_parts", since = "CURRENT_RUSTC_VERSION")]
802787
pub fn into_raw_parts(self) -> (*mut T, usize, usize) {
803788
let mut me = ManuallyDrop::new(self);
804789
(me.as_mut_ptr(), me.len(), me.capacity())
@@ -823,7 +808,7 @@ impl<T> Vec<T> {
823808
/// # Examples
824809
///
825810
/// ```
826-
/// #![feature(vec_into_raw_parts, box_vec_non_null)]
811+
/// #![feature(box_vec_non_null)]
827812
///
828813
/// let v: Vec<i32> = vec![-1, 0, 1];
829814
///
@@ -840,7 +825,6 @@ impl<T> Vec<T> {
840825
/// ```
841826
#[must_use = "losing the pointer will leak memory"]
842827
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
843-
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
844828
pub fn into_parts(self) -> (NonNull<T>, usize, usize) {
845829
let (ptr, len, capacity) = self.into_raw_parts();
846830
// SAFETY: A `Vec` always has a non-null pointer.
@@ -996,7 +980,6 @@ impl<T, A: Allocator> Vec<T, A> {
996980
///
997981
/// # Examples
998982
///
999-
// FIXME Update this when vec_into_raw_parts is stabilized
1000983
/// ```
1001984
/// #![feature(allocator_api)]
1002985
///
@@ -1010,15 +993,8 @@ impl<T, A: Allocator> Vec<T, A> {
1010993
/// v.push(2);
1011994
/// v.push(3);
1012995
///
1013-
/// // Prevent running `v`'s destructor so we are in complete control
1014-
/// // of the allocation.
1015-
/// let mut v = mem::ManuallyDrop::new(v);
1016-
///
1017-
/// // Pull out the various important pieces of information about `v`
1018-
/// let p = v.as_mut_ptr();
1019-
/// let len = v.len();
1020-
/// let cap = v.capacity();
1021-
/// let alloc = v.allocator();
996+
/// // Deconstruct the vector into parts.
997+
/// let (p, len, cap, alloc) = v.into_raw_parts_with_alloc();
1022998
///
1023999
/// unsafe {
10241000
/// // Overwrite memory with 4, 5, 6
@@ -1116,7 +1092,6 @@ impl<T, A: Allocator> Vec<T, A> {
11161092
///
11171093
/// # Examples
11181094
///
1119-
// FIXME Update this when vec_into_raw_parts is stabilized
11201095
/// ```
11211096
/// #![feature(allocator_api, box_vec_non_null)]
11221097
///
@@ -1130,15 +1105,8 @@ impl<T, A: Allocator> Vec<T, A> {
11301105
/// v.push(2);
11311106
/// v.push(3);
11321107
///
1133-
/// // Prevent running `v`'s destructor so we are in complete control
1134-
/// // of the allocation.
1135-
/// let mut v = mem::ManuallyDrop::new(v);
1136-
///
1137-
/// // Pull out the various important pieces of information about `v`
1138-
/// let p = unsafe { NonNull::new_unchecked(v.as_mut_ptr()) };
1139-
/// let len = v.len();
1140-
/// let cap = v.capacity();
1141-
/// let alloc = v.allocator();
1108+
/// // Deconstruct the vector into parts.
1109+
/// let (p, len, cap, alloc) = v.into_parts_with_alloc();
11421110
///
11431111
/// unsafe {
11441112
/// // Overwrite memory with 4, 5, 6
@@ -1206,7 +1174,7 @@ impl<T, A: Allocator> Vec<T, A> {
12061174
/// # Examples
12071175
///
12081176
/// ```
1209-
/// #![feature(allocator_api, vec_into_raw_parts)]
1177+
/// #![feature(allocator_api)]
12101178
///
12111179
/// use std::alloc::System;
12121180
///
@@ -1228,7 +1196,6 @@ impl<T, A: Allocator> Vec<T, A> {
12281196
/// ```
12291197
#[must_use = "losing the pointer will leak memory"]
12301198
#[unstable(feature = "allocator_api", issue = "32838")]
1231-
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
12321199
pub fn into_raw_parts_with_alloc(self) -> (*mut T, usize, usize, A) {
12331200
let mut me = ManuallyDrop::new(self);
12341201
let len = me.len();
@@ -1256,7 +1223,7 @@ impl<T, A: Allocator> Vec<T, A> {
12561223
/// # Examples
12571224
///
12581225
/// ```
1259-
/// #![feature(allocator_api, vec_into_raw_parts, box_vec_non_null)]
1226+
/// #![feature(allocator_api, box_vec_non_null)]
12601227
///
12611228
/// use std::alloc::System;
12621229
///
@@ -1279,7 +1246,6 @@ impl<T, A: Allocator> Vec<T, A> {
12791246
#[must_use = "losing the pointer will leak memory"]
12801247
#[unstable(feature = "allocator_api", issue = "32838")]
12811248
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1282-
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
12831249
pub fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) {
12841250
let (ptr, len, capacity, alloc) = self.into_raw_parts_with_alloc();
12851251
// SAFETY: A `Vec` always has a non-null pointer.

library/core/src/intrinsics/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,9 @@ pub const fn forget<T: ?Sized>(_: T);
769769
/// // in terms of converting the original inner type (`&i32`) to the new one (`Option<&i32>`),
770770
/// // this has all the same caveats. Besides the information provided above, also consult the
771771
/// // [`from_raw_parts`] documentation.
772+
/// let (ptr, len, capacity) = v_clone.into_raw_parts();
772773
/// let v_from_raw = unsafe {
773-
// FIXME Update this when vec_into_raw_parts is stabilized
774-
/// // Ensure the original vector is not dropped.
775-
/// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
776-
/// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
777-
/// v_clone.len(),
778-
/// v_clone.capacity())
774+
/// Vec::from_raw_parts(ptr.cast::<*mut Option<&i32>>(), len, capacity)
779775
/// };
780776
/// ```
781777
///

library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,6 @@
381381
#![feature(try_reserve_kind)]
382382
#![feature(try_with_capacity)]
383383
#![feature(unique_rc_arc)]
384-
#![feature(vec_into_raw_parts)]
385384
#![feature(wtf8_internals)]
386385
// tidy-alphabetical-end
387386
//

0 commit comments

Comments
 (0)