diff options
| author | CAD97 <cad97@cad97.com> | 2020-02-21 15:38:29 -0500 |
|---|---|---|
| committer | CAD97 <cad97@cad97.com> | 2020-04-08 02:09:47 -0400 |
| commit | 1b76bb03fe9fd0803efeea9964b61d3c1b7e96ae (patch) | |
| tree | 423f0de5cccdaaa04fb5bec66e33d6a89769822f /src/libcore/alloc/layout.rs | |
| parent | 42abbd8878d3b67238f3611b0587c704ba94f39c (diff) | |
| download | rust-1b76bb03fe9fd0803efeea9964b61d3c1b7e96ae.tar.gz rust-1b76bb03fe9fd0803efeea9964b61d3c1b7e96ae.zip | |
Stabilize some of alloc_layout_extras
Diffstat (limited to 'src/libcore/alloc/layout.rs')
| -rw-r--r-- | src/libcore/alloc/layout.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/libcore/alloc/layout.rs b/src/libcore/alloc/layout.rs index fa644cfe99e..98f9054588a 100644 --- a/src/libcore/alloc/layout.rs +++ b/src/libcore/alloc/layout.rs @@ -162,7 +162,7 @@ impl Layout { /// Returns an error if the combination of `self.size()` and the given /// `align` violates the conditions listed in /// [`Layout::from_size_align`](#method.from_size_align). - #[unstable(feature = "alloc_layout_extra", issue = "55724")] + #[stable(feature = "alloc_layout_manipulation", since = "1.44.0")] #[inline] pub fn align_to(&self, align: usize) -> Result<Self, LayoutErr> { Layout::from_size_align(self.size(), cmp::max(self.align(), align)) @@ -218,7 +218,7 @@ impl Layout { /// /// This is equivalent to adding the result of `padding_needed_for` /// to the layout's current size. - #[unstable(feature = "alloc_layout_extra", issue = "55724")] + #[stable(feature = "alloc_layout_manipulation", since = "1.44.0")] #[inline] pub fn pad_to_align(&self) -> Layout { let pad = self.padding_needed_for(self.align()); @@ -258,19 +258,17 @@ impl Layout { /// Creates a layout describing the record for `self` followed by /// `next`, including any necessary padding to ensure that `next` - /// will be properly aligned. Note that the resulting layout will - /// satisfy the alignment properties of both `self` and `next`. - /// - /// The resulting layout will be the same as that of a C struct containing - /// two fields with the layouts of `self` and `next`, in that order. + /// will be properly aligned, but no trailing padding. Note that + /// the resulting layout will satisfy the alignment properties of + /// both `self` and `next`, in order to ensure field alignment. /// - /// Returns `Some((k, offset))`, where `k` is layout of the concatenated + /// Returns `Ok((k, offset))`, where `k` is layout of the concatenated /// record and `offset` is the relative location, in bytes, of the /// start of the `next` embedded within the concatenated record /// (assuming that the record itself starts at offset 0). /// /// On arithmetic overflow, returns `LayoutErr`. - #[unstable(feature = "alloc_layout_extra", issue = "55724")] + #[stable(feature = "alloc_layout_manipulation", since = "1.44.0")] #[inline] pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutErr> { let new_align = cmp::max(self.align(), next.align()); @@ -318,13 +316,12 @@ impl Layout { /// Creates a layout describing the record for a `[T; n]`. /// /// On arithmetic overflow, returns `LayoutErr`. - #[unstable(feature = "alloc_layout_extra", issue = "55724")] + #[stable(feature = "alloc_layout_manipulation", since = "1.44.0")] #[inline] pub fn array<T>(n: usize) -> Result<Self, LayoutErr> { - Layout::new::<T>().repeat(n).map(|(k, offs)| { - debug_assert!(offs == mem::size_of::<T>()); - k - }) + let (layout, offset) = Layout::new::<T>().repeat(n)?; + debug_assert_eq!(offset, mem::size_of::<T>()); + Ok(layout.pad_to_align()) } } |
