Skip to content

Commit 1b76bb0

Browse files
committed
Stabilize some of alloc_layout_extras
1 parent 42abbd8 commit 1b76bb0

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/libcore/alloc/layout.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Layout {
162162
/// Returns an error if the combination of `self.size()` and the given
163163
/// `align` violates the conditions listed in
164164
/// [`Layout::from_size_align`](#method.from_size_align).
165-
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
165+
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
166166
#[inline]
167167
pub fn align_to(&self, align: usize) -> Result<Self, LayoutErr> {
168168
Layout::from_size_align(self.size(), cmp::max(self.align(), align))
@@ -218,7 +218,7 @@ impl Layout {
218218
///
219219
/// This is equivalent to adding the result of `padding_needed_for`
220220
/// to the layout's current size.
221-
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
221+
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
222222
#[inline]
223223
pub fn pad_to_align(&self) -> Layout {
224224
let pad = self.padding_needed_for(self.align());
@@ -258,19 +258,17 @@ impl Layout {
258258

259259
/// Creates a layout describing the record for `self` followed by
260260
/// `next`, including any necessary padding to ensure that `next`
261-
/// will be properly aligned. Note that the resulting layout will
262-
/// satisfy the alignment properties of both `self` and `next`.
263-
///
264-
/// The resulting layout will be the same as that of a C struct containing
265-
/// two fields with the layouts of `self` and `next`, in that order.
261+
/// will be properly aligned, but no trailing padding. Note that
262+
/// the resulting layout will satisfy the alignment properties of
263+
/// both `self` and `next`, in order to ensure field alignment.
266264
///
267-
/// Returns `Some((k, offset))`, where `k` is layout of the concatenated
265+
/// Returns `Ok((k, offset))`, where `k` is layout of the concatenated
268266
/// record and `offset` is the relative location, in bytes, of the
269267
/// start of the `next` embedded within the concatenated record
270268
/// (assuming that the record itself starts at offset 0).
271269
///
272270
/// On arithmetic overflow, returns `LayoutErr`.
273-
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
271+
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
274272
#[inline]
275273
pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutErr> {
276274
let new_align = cmp::max(self.align(), next.align());
@@ -318,13 +316,12 @@ impl Layout {
318316
/// Creates a layout describing the record for a `[T; n]`.
319317
///
320318
/// On arithmetic overflow, returns `LayoutErr`.
321-
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
319+
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
322320
#[inline]
323321
pub fn array<T>(n: usize) -> Result<Self, LayoutErr> {
324-
Layout::new::<T>().repeat(n).map(|(k, offs)| {
325-
debug_assert!(offs == mem::size_of::<T>());
326-
k
327-
})
322+
let (layout, offset) = Layout::new::<T>().repeat(n)?;
323+
debug_assert_eq!(offset, mem::size_of::<T>());
324+
Ok(layout.pad_to_align())
328325
}
329326
}
330327

0 commit comments

Comments
 (0)