Skip to content

Commit 5f6fc9d

Browse files
authored
Unrolled build for #148827
Rollup merge of #148827 - GoldsteinE:stabilize-vec-into-raw-parts, r=Mark-Simulacrum Stabilize vec_into_raw_parts This stabilizes `Vec::into_raw_parts()` and `String::into_raw_parts()` per FCP in #65816 (comment). While this _does not_ stabilize `Vec::into_parts()`, I fixed up the examples that said they were waiting for `vec_into_raw_parts`. As `Vec::from_parts()` and `Vec::into_parts()` are covered by the same feature `box_vec_non_null`, any doctest that uses `Vec::from_parts()` can also use `Vec::into_parts()` (and same for allocator-aware versions). Closes #65816 ``@rustbot`` modify labels: +T-libs-api
2 parents 54f4176 + ac9bb13 commit 5f6fc9d

File tree

4 files changed

+19
-81
lines changed

4 files changed

+19
-81
lines changed

library/alloc/src/string.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -265,18 +265,11 @@ 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
/// ```
270-
/// use std::mem;
271-
///
272269
/// let story = String::from("Once upon a time...");
273270
///
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();
271+
/// // Deconstruct the String into parts.
272+
/// let (ptr, len, capacity) = story.into_raw_parts();
280273
///
281274
/// // story has nineteen bytes
282275
/// assert_eq!(19, len);
@@ -932,7 +925,6 @@ impl String {
932925
/// # Examples
933926
///
934927
/// ```
935-
/// #![feature(vec_into_raw_parts)]
936928
/// let s = String::from("hello");
937929
///
938930
/// let (ptr, len, cap) = s.into_raw_parts();
@@ -941,7 +933,7 @@ impl String {
941933
/// assert_eq!(rebuilt, "hello");
942934
/// ```
943935
#[must_use = "losing the pointer will leak memory"]
944-
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
936+
#[stable(feature = "vec_into_raw_parts", since = "CURRENT_RUSTC_VERSION")]
945937
pub fn into_raw_parts(self) -> (*mut u8, usize, usize) {
946938
self.vec.into_raw_parts()
947939
}
@@ -970,19 +962,12 @@ impl String {
970962
///
971963
/// # Examples
972964
///
973-
// FIXME Update this when vec_into_raw_parts is stabilized
974965
/// ```
975-
/// use std::mem;
976-
///
977966
/// unsafe {
978967
/// let s = String::from("hello");
979968
///
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();
969+
/// // Deconstruct the String into parts.
970+
/// let (ptr, len, capacity) = s.into_raw_parts();
986971
///
987972
/// let s = String::from_raw_parts(ptr, len, capacity);
988973
///

library/alloc/src/vec/mod.rs

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -592,21 +592,13 @@ impl<T> Vec<T> {
592592
///
593593
/// # Examples
594594
///
595-
// FIXME Update this when vec_into_raw_parts is stabilized
596595
/// ```
597596
/// use std::ptr;
598-
/// use std::mem;
599597
///
600598
/// let v = vec![1, 2, 3];
601599
///
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();
600+
/// // Deconstruct the vector into parts.
601+
/// let (p, len, cap) = v.into_raw_parts();
610602
///
611603
/// unsafe {
612604
/// // Overwrite memory with 4, 5, 6
@@ -700,23 +692,13 @@ impl<T> Vec<T> {
700692
///
701693
/// # Examples
702694
///
703-
// FIXME Update this when vec_into_raw_parts is stabilized
704695
/// ```
705696
/// #![feature(box_vec_non_null)]
706697
///
707-
/// use std::ptr::NonNull;
708-
/// use std::mem;
709-
///
710698
/// let v = vec![1, 2, 3];
711699
///
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();
700+
/// // Deconstruct the vector into parts.
701+
/// let (p, len, cap) = v.into_parts();
720702
///
721703
/// unsafe {
722704
/// // Overwrite memory with 4, 5, 6
@@ -783,7 +765,6 @@ impl<T> Vec<T> {
783765
/// # Examples
784766
///
785767
/// ```
786-
/// #![feature(vec_into_raw_parts)]
787768
/// let v: Vec<i32> = vec![-1, 0, 1];
788769
///
789770
/// let (ptr, len, cap) = v.into_raw_parts();
@@ -798,7 +779,7 @@ impl<T> Vec<T> {
798779
/// assert_eq!(rebuilt, [4294967295, 0, 1]);
799780
/// ```
800781
#[must_use = "losing the pointer will leak memory"]
801-
#[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
782+
#[stable(feature = "vec_into_raw_parts", since = "CURRENT_RUSTC_VERSION")]
802783
pub fn into_raw_parts(self) -> (*mut T, usize, usize) {
803784
let mut me = ManuallyDrop::new(self);
804785
(me.as_mut_ptr(), me.len(), me.capacity())
@@ -823,7 +804,7 @@ impl<T> Vec<T> {
823804
/// # Examples
824805
///
825806
/// ```
826-
/// #![feature(vec_into_raw_parts, box_vec_non_null)]
807+
/// #![feature(box_vec_non_null)]
827808
///
828809
/// let v: Vec<i32> = vec![-1, 0, 1];
829810
///
@@ -840,7 +821,6 @@ impl<T> Vec<T> {
840821
/// ```
841822
#[must_use = "losing the pointer will leak memory"]
842823
#[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
843-
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
844824
pub fn into_parts(self) -> (NonNull<T>, usize, usize) {
845825
let (ptr, len, capacity) = self.into_raw_parts();
846826
// SAFETY: A `Vec` always has a non-null pointer.
@@ -996,29 +976,20 @@ impl<T, A: Allocator> Vec<T, A> {
996976
///
997977
/// # Examples
998978
///
999-
// FIXME Update this when vec_into_raw_parts is stabilized
1000979
/// ```
1001980
/// #![feature(allocator_api)]
1002981
///
1003982
/// use std::alloc::System;
1004983
///
1005984
/// use std::ptr;
1006-
/// use std::mem;
1007985
///
1008986
/// let mut v = Vec::with_capacity_in(3, System);
1009987
/// v.push(1);
1010988
/// v.push(2);
1011989
/// v.push(3);
1012990
///
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();
991+
/// // Deconstruct the vector into parts.
992+
/// let (p, len, cap, alloc) = v.into_raw_parts_with_alloc();
1022993
///
1023994
/// unsafe {
1024995
/// // Overwrite memory with 4, 5, 6
@@ -1116,29 +1087,18 @@ impl<T, A: Allocator> Vec<T, A> {
11161087
///
11171088
/// # Examples
11181089
///
1119-
// FIXME Update this when vec_into_raw_parts is stabilized
11201090
/// ```
11211091
/// #![feature(allocator_api, box_vec_non_null)]
11221092
///
11231093
/// use std::alloc::System;
11241094
///
1125-
/// use std::ptr::NonNull;
1126-
/// use std::mem;
1127-
///
11281095
/// let mut v = Vec::with_capacity_in(3, System);
11291096
/// v.push(1);
11301097
/// v.push(2);
11311098
/// v.push(3);
11321099
///
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();
1100+
/// // Deconstruct the vector into parts.
1101+
/// let (p, len, cap, alloc) = v.into_parts_with_alloc();
11421102
///
11431103
/// unsafe {
11441104
/// // Overwrite memory with 4, 5, 6
@@ -1206,7 +1166,7 @@ impl<T, A: Allocator> Vec<T, A> {
12061166
/// # Examples
12071167
///
12081168
/// ```
1209-
/// #![feature(allocator_api, vec_into_raw_parts)]
1169+
/// #![feature(allocator_api)]
12101170
///
12111171
/// use std::alloc::System;
12121172
///
@@ -1228,7 +1188,6 @@ impl<T, A: Allocator> Vec<T, A> {
12281188
/// ```
12291189
#[must_use = "losing the pointer will leak memory"]
12301190
#[unstable(feature = "allocator_api", issue = "32838")]
1231-
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
12321191
pub fn into_raw_parts_with_alloc(self) -> (*mut T, usize, usize, A) {
12331192
let mut me = ManuallyDrop::new(self);
12341193
let len = me.len();
@@ -1256,7 +1215,7 @@ impl<T, A: Allocator> Vec<T, A> {
12561215
/// # Examples
12571216
///
12581217
/// ```
1259-
/// #![feature(allocator_api, vec_into_raw_parts, box_vec_non_null)]
1218+
/// #![feature(allocator_api, box_vec_non_null)]
12601219
///
12611220
/// use std::alloc::System;
12621221
///
@@ -1279,7 +1238,6 @@ impl<T, A: Allocator> Vec<T, A> {
12791238
#[must_use = "losing the pointer will leak memory"]
12801239
#[unstable(feature = "allocator_api", issue = "32838")]
12811240
// #[unstable(feature = "box_vec_non_null", reason = "new API", issue = "130364")]
1282-
// #[unstable(feature = "vec_into_raw_parts", reason = "new API", issue = "65816")]
12831241
pub fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) {
12841242
let (ptr, len, capacity, alloc) = self.into_raw_parts_with_alloc();
12851243
// 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
@@ -382,7 +382,6 @@
382382
#![feature(try_reserve_kind)]
383383
#![feature(try_with_capacity)]
384384
#![feature(unique_rc_arc)]
385-
#![feature(vec_into_raw_parts)]
386385
#![feature(wtf8_internals)]
387386
// tidy-alphabetical-end
388387
//

0 commit comments

Comments
 (0)