diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index f9af752cae6c..252b1c5a6dc7 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -2176,18 +2176,19 @@ impl AsRef for Rc { impl Unpin for Rc { } unsafe fn data_offset(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::>(); - (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() -> isize { - let align = align_of::(); + data_offset_align(align_of::()) +} + +fn data_offset_align(align: usize) -> isize { let layout = Layout::new::>(); (layout.size() + layout.padding_needed_for(align)) as isize }