diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-02 10:27:20 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-02 10:27:20 +0200 |
| commit | 2a3766e7feb9ff751a882e5a353f2d3ee87a85de (patch) | |
| tree | 8d5257d68bb2077c8858ff86f7cc8f853af0fd2f | |
| parent | be6e38c617d39b3b1e9ac8a3fe606cb5d72ca6af (diff) | |
| parent | 9a67df290c7d2a5b94d8095a13c472171202f544 (diff) | |
| download | rust-2a3766e7feb9ff751a882e5a353f2d3ee87a85de.tar.gz rust-2a3766e7feb9ff751a882e5a353f2d3ee87a85de.zip | |
Rollup merge of #113147 - lizhanhui:fix_vec_from_raw_parts_doc_example, r=Mark-Simulacrum
Fix document examples of Vec::from_raw_parts and Vec::from_raw_parts_in These two examples are misplaced.
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index ef4f8be6f19..598ecf05e82 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -560,22 +560,20 @@ impl<T> Vec<T> { /// Using memory that was allocated elsewhere: /// /// ```rust - /// #![feature(allocator_api)] - /// - /// use std::alloc::{AllocError, Allocator, Global, Layout}; + /// use std::alloc::{alloc, Layout}; /// /// fn main() { /// let layout = Layout::array::<u32>(16).expect("overflow cannot happen"); /// /// let vec = unsafe { - /// let mem = match Global.allocate(layout) { - /// Ok(mem) => mem.cast::<u32>().as_ptr(), - /// Err(AllocError) => return, - /// }; + /// let mem = alloc(layout).cast::<u32>(); + /// if mem.is_null() { + /// return; + /// } /// /// mem.write(1_000_000); /// - /// Vec::from_raw_parts_in(mem, 1, 16, Global) + /// Vec::from_raw_parts(mem, 1, 16) /// }; /// /// assert_eq!(vec, &[1_000_000]); @@ -758,19 +756,22 @@ impl<T, A: Allocator> Vec<T, A> { /// Using memory that was allocated elsewhere: /// /// ```rust - /// use std::alloc::{alloc, Layout}; + /// #![feature(allocator_api)] + /// + /// use std::alloc::{AllocError, Allocator, Global, Layout}; /// /// fn main() { /// let layout = Layout::array::<u32>(16).expect("overflow cannot happen"); + /// /// let vec = unsafe { - /// let mem = alloc(layout).cast::<u32>(); - /// if mem.is_null() { - /// return; - /// } + /// let mem = match Global.allocate(layout) { + /// Ok(mem) => mem.cast::<u32>().as_ptr(), + /// Err(AllocError) => return, + /// }; /// /// mem.write(1_000_000); /// - /// Vec::from_raw_parts(mem, 1, 16) + /// Vec::from_raw_parts_in(mem, 1, 16, Global) /// }; /// /// assert_eq!(vec, &[1_000_000]); |
