Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a comment on the usage of Layout::new::<RcBox<()>>()
  • Loading branch information
SimonSapin committed Aug 16, 2019
commit ae1e201a0cd37a48bd3dabf1c643ccd5f53f7680
2 changes: 2 additions & 0 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down