about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/rc.rs2
-rw-r--r--src/liballoc/sync.rs2
2 files changed, 4 insertions, 0 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index a9aa822173f..9d608c886b8 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -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)
diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs
index 50fd9850893..1bd177be0d5 100644
--- a/src/liballoc/sync.rs
+++ b/src/liballoc/sync.rs
@@ -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)