|
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")] |
3 | 2 |
|
4 | 3 | use core::alloc::LayoutError; |
5 | 4 | use core::cmp; |
@@ -50,7 +49,7 @@ enum AllocInit { |
50 | 49 | /// `usize::MAX`. This means that you need to be careful when round-tripping this type with a |
51 | 50 | /// `Box<[T]>`, since `capacity()` won't yield the length. |
52 | 51 | #[allow(missing_debug_implementations)] |
53 | | -pub struct RawVec<T, A: Allocator = Global> { |
| 52 | +pub(crate) struct RawVec<T, A: Allocator = Global> { |
54 | 53 | ptr: Unique<T>, |
55 | 54 | cap: usize, |
56 | 55 | alloc: A, |
@@ -87,33 +86,20 @@ impl<T> RawVec<T, Global> { |
87 | 86 | /// # Aborts |
88 | 87 | /// |
89 | 88 | /// Aborts on OOM. |
90 | | - #[cfg(not(no_global_oom_handling))] |
| 89 | + #[cfg(not(any(no_global_oom_handling, test)))] |
91 | 90 | #[must_use] |
92 | 91 | #[inline] |
93 | 92 | pub fn with_capacity(capacity: usize) -> Self { |
94 | 93 | Self::with_capacity_in(capacity, Global) |
95 | 94 | } |
96 | 95 |
|
97 | 96 | /// 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)))] |
99 | 98 | #[must_use] |
100 | 99 | #[inline] |
101 | 100 | pub fn with_capacity_zeroed(capacity: usize) -> Self { |
102 | 101 | Self::with_capacity_zeroed_in(capacity, Global) |
103 | 102 | } |
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 | | - } |
117 | 103 | } |
118 | 104 |
|
119 | 105 | impl<T, A: Allocator> RawVec<T, A> { |
@@ -154,14 +140,6 @@ impl<T, A: Allocator> RawVec<T, A> { |
154 | 140 | Self::allocate_in(capacity, AllocInit::Zeroed, alloc) |
155 | 141 | } |
156 | 142 |
|
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 | | - |
165 | 143 | /// Converts the entire buffer into `Box<[MaybeUninit<T>]>` with the specified `len`. |
166 | 144 | /// |
167 | 145 | /// Note that this will correctly reconstitute any `cap` changes |
@@ -290,37 +268,6 @@ impl<T, A: Allocator> RawVec<T, A> { |
290 | 268 | /// # Aborts |
291 | 269 | /// |
292 | 270 | /// 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 | | - /// ``` |
324 | 271 | #[cfg(not(no_global_oom_handling))] |
325 | 272 | #[inline] |
326 | 273 | pub fn reserve(&mut self, len: usize, additional: usize) { |
|
0 commit comments