Skip to content

Commit 1b12d01

Browse files
committed
Auto merge of #90542 - the8472:privatize-the-means-of-rawvec-production, r=joshtriplett
Make RawVec private to alloc RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since it is no longer used outside alloc itself it can be made private again. Also remove some functions that are dead due to lack of internal users.
2 parents 3e018ce + 7afe6f5 commit 1b12d01

File tree

2 files changed

+6
-58
lines changed

2 files changed

+6
-58
lines changed

library/alloc/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ extern crate test;
174174
#[macro_use]
175175
mod macros;
176176

177+
mod raw_vec;
178+
177179
// Heaps provided for low-level allocation strategies
178180

179181
pub mod alloc;
@@ -192,7 +194,6 @@ mod boxed {
192194
pub mod borrow;
193195
pub mod collections;
194196
pub mod fmt;
195-
pub mod raw_vec;
196197
pub mod rc;
197198
pub mod slice;
198199
pub mod str;

library/alloc/src/raw_vec.rs

+4-57
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "none")]
2-
#![doc(hidden)]
1+
#![unstable(feature = "raw_vec_internals", reason = "unstable const warnings", issue = "none")]
32

43
use core::alloc::LayoutError;
54
use core::cmp;
@@ -50,7 +49,7 @@ enum AllocInit {
5049
/// `usize::MAX`. This means that you need to be careful when round-tripping this type with a
5150
/// `Box<[T]>`, since `capacity()` won't yield the length.
5251
#[allow(missing_debug_implementations)]
53-
pub struct RawVec<T, A: Allocator = Global> {
52+
pub(crate) struct RawVec<T, A: Allocator = Global> {
5453
ptr: Unique<T>,
5554
cap: usize,
5655
alloc: A,
@@ -87,33 +86,20 @@ impl<T> RawVec<T, Global> {
8786
/// # Aborts
8887
///
8988
/// Aborts on OOM.
90-
#[cfg(not(no_global_oom_handling))]
89+
#[cfg(not(any(no_global_oom_handling, test)))]
9190
#[must_use]
9291
#[inline]
9392
pub fn with_capacity(capacity: usize) -> Self {
9493
Self::with_capacity_in(capacity, Global)
9594
}
9695

9796
/// Like `with_capacity`, but guarantees the buffer is zeroed.
98-
#[cfg(not(no_global_oom_handling))]
97+
#[cfg(not(any(no_global_oom_handling, test)))]
9998
#[must_use]
10099
#[inline]
101100
pub fn with_capacity_zeroed(capacity: usize) -> Self {
102101
Self::with_capacity_zeroed_in(capacity, Global)
103102
}
104-
105-
/// Reconstitutes a `RawVec` from a pointer and capacity.
106-
///
107-
/// # Safety
108-
///
109-
/// The `ptr` must be allocated (on the system heap), and with the given `capacity`.
110-
/// The `capacity` cannot exceed `isize::MAX` for sized types. (only a concern on 32-bit
111-
/// systems). ZST vectors may have a capacity up to `usize::MAX`.
112-
/// If the `ptr` and `capacity` come from a `RawVec`, then this is guaranteed.
113-
#[inline]
114-
pub unsafe fn from_raw_parts(ptr: *mut T, capacity: usize) -> Self {
115-
unsafe { Self::from_raw_parts_in(ptr, capacity, Global) }
116-
}
117103
}
118104

119105
impl<T, A: Allocator> RawVec<T, A> {
@@ -154,14 +140,6 @@ impl<T, A: Allocator> RawVec<T, A> {
154140
Self::allocate_in(capacity, AllocInit::Zeroed, alloc)
155141
}
156142

157-
/// Converts a `Box<[T]>` into a `RawVec<T>`.
158-
pub fn from_box(slice: Box<[T], A>) -> Self {
159-
unsafe {
160-
let (slice, alloc) = Box::into_raw_with_allocator(slice);
161-
RawVec::from_raw_parts_in(slice.as_mut_ptr(), slice.len(), alloc)
162-
}
163-
}
164-
165143
/// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`.
166144
///
167145
/// Note that this will correctly reconstitute any `cap` changes
@@ -290,37 +268,6 @@ impl<T, A: Allocator> RawVec<T, A> {
290268
/// # Aborts
291269
///
292270
/// Aborts on OOM.
293-
///
294-
/// # Examples
295-
///
296-
/// ```
297-
/// # #![feature(raw_vec_internals)]
298-
/// # extern crate alloc;
299-
/// # use std::ptr;
300-
/// # use alloc::raw_vec::RawVec;
301-
/// struct MyVec<T> {
302-
/// buf: RawVec<T>,
303-
/// len: usize,
304-
/// }
305-
///
306-
/// impl<T: Clone> MyVec<T> {
307-
/// pub fn push_all(&mut self, elems: &[T]) {
308-
/// self.buf.reserve(self.len, elems.len());
309-
/// // reserve would have aborted or panicked if the len exceeded
310-
/// // `isize::MAX` so this is safe to do unchecked now.
311-
/// for x in elems {
312-
/// unsafe {
313-
/// ptr::write(self.buf.ptr().add(self.len), x.clone());
314-
/// }
315-
/// self.len += 1;
316-
/// }
317-
/// }
318-
/// }
319-
/// # fn main() {
320-
/// # let mut vector = MyVec { buf: RawVec::new(), len: 0 };
321-
/// # vector.push_all(&[1, 3, 5, 7, 9]);
322-
/// # }
323-
/// ```
324271
#[cfg(not(no_global_oom_handling))]
325272
#[inline]
326273
pub fn reserve(&mut self, len: usize, additional: usize) {

0 commit comments

Comments
 (0)