Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae1e201

Browse files
committedAug 16, 2019
Add a comment on the usage of Layout::new::<RcBox<()>>()
1 parent 78264f5 commit ae1e201

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed
 

‎src/liballoc/rc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ impl<T> Rc<[T]> {
441441
#[unstable(feature = "new_uninit", issue = "63291")]
442442
pub fn new_uninit_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
443443
let data_layout = Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
444+
// This relies on `value` being the last field of `RcBox` in memory,
445+
// so that the layout of `RcBox<T>` is the same as that of `RcBox<()>` followed by `T`.
444446
let (layout, offset) = Layout::new::<RcBox<()>>().extend(data_layout).unwrap();
445447
unsafe {
446448
let allocated_ptr = Global.alloc(layout)

‎src/liballoc/sync.rs

+2
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ impl<T> Arc<[T]> {
425425
#[unstable(feature = "new_uninit", issue = "63291")]
426426
pub fn new_uninit_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
427427
let data_layout = Layout::array::<mem::MaybeUninit<T>>(len).unwrap();
428+
// This relies on `value` being the last field of `RcBox` in memory,
429+
// so that the layout of `RcBox<T>` is the same as that of `RcBox<()>` followed by `T`.
428430
let (layout, offset) = Layout::new::<ArcInner<()>>().extend(data_layout).unwrap();
429431
unsafe {
430432
let allocated_ptr = Global.alloc(layout)

0 commit comments

Comments
 (0)
Please sign in to comment.