mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Add a comment on the usage of Layout:🆕:<RcBox<()>>()
This commit is contained in:
parent
78264f5e3c
commit
ae1e201a0c
@ -441,6 +441,8 @@ impl<T> Rc<[T]> {
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
pub fn new_uninit_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
|
||||
let data_layout = Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
|
||||
// This relies on `value` being the last field of `RcBox` in memory,
|
||||
// so that the layout of `RcBox<T>` is the same as that of `RcBox<()>` followed by `T`.
|
||||
let (layout, offset) = Layout::new::<RcBox<()>>().extend(data_layout).unwrap();
|
||||
unsafe {
|
||||
let allocated_ptr = Global.alloc(layout)
|
||||
|
@ -425,6 +425,8 @@ impl<T> Arc<[T]> {
|
||||
#[unstable(feature = "new_uninit", issue = "63291")]
|
||||
pub fn new_uninit_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
|
||||
let data_layout = Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
|
||||
// This relies on `value` being the last field of `RcBox` in memory,
|
||||
// so that the layout of `RcBox<T>` is the same as that of `RcBox<()>` followed by `T`.
|
||||
let (layout, offset) = Layout::new::<ArcInner<()>>().extend(data_layout).unwrap();
|
||||
unsafe {
|
||||
let allocated_ptr = Global.alloc(layout)
|
||||
|
Loading…
Reference in New Issue
Block a user