diff options
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index f9af752cae6..252b1c5a6dc 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -2176,18 +2176,19 @@ impl<T: ?Sized> AsRef<T> for Rc<T> { impl<T: ?Sized> Unpin for Rc<T> { } unsafe fn data_offset<T: ?Sized>(ptr: *const T) -> isize { - // Align the unsized value to the end of the RcBox. + // Align the unsized value to the end of the `RcBox`. // Because it is ?Sized, it will always be the last field in memory. - let align = align_of_val(&*ptr); - let layout = Layout::new::<RcBox<()>>(); - (layout.size() + layout.padding_needed_for(align)) as isize + data_offset_align(align_of_val(&*ptr)) } -/// Computes the offset of the data field within ArcInner. +/// Computes the offset of the data field within `RcBox`. /// /// Unlike [`data_offset`], this doesn't need the pointer, but it works only on `T: Sized`. fn data_offset_sized<T>() -> isize { - let align = align_of::<T>(); + data_offset_align(align_of::<T>()) +} + +fn data_offset_align(align: usize) -> isize { let layout = Layout::new::<RcBox<()>>(); (layout.size() + layout.padding_needed_for(align)) as isize } |
