Skip to content

Commit a97abb4

Browse files
author
Jacob Hughes
committed
Rename LayoutErr to LayoutError in core
1 parent d9985fc commit a97abb4

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

library/core/src/alloc/layout.rs

+28-25
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Layout {
3939

4040
impl Layout {
4141
/// Constructs a `Layout` from a given `size` and `align`,
42-
/// or returns `LayoutErr` if any of the following conditions
42+
/// or returns `LayoutError` if any of the following conditions
4343
/// are not met:
4444
///
4545
/// * `align` must not be zero,
@@ -52,9 +52,9 @@ impl Layout {
5252
#[stable(feature = "alloc_layout", since = "1.28.0")]
5353
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
5454
#[inline]
55-
pub const fn from_size_align(size: usize, align: usize) -> Result<Self, LayoutErr> {
55+
pub const fn from_size_align(size: usize, align: usize) -> Result<Self, LayoutError> {
5656
if !align.is_power_of_two() {
57-
return Err(LayoutErr { private: () });
57+
return Err(LayoutError { private: () });
5858
}
5959

6060
// (power-of-two implies align != 0.)
@@ -72,7 +72,7 @@ impl Layout {
7272
// Above implies that checking for summation overflow is both
7373
// necessary and sufficient.
7474
if size > usize::MAX - (align - 1) {
75-
return Err(LayoutErr { private: () });
75+
return Err(LayoutError { private: () });
7676
}
7777

7878
// SAFETY: the conditions for `from_size_align_unchecked` have been
@@ -200,7 +200,7 @@ impl Layout {
200200
/// `align` violates the conditions listed in [`Layout::from_size_align`].
201201
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
202202
#[inline]
203-
pub fn align_to(&self, align: usize) -> Result<Self, LayoutErr> {
203+
pub fn align_to(&self, align: usize) -> Result<Self, LayoutError> {
204204
Layout::from_size_align(self.size(), cmp::max(self.align(), align))
205205
}
206206

@@ -274,16 +274,16 @@ impl Layout {
274274
/// layout of the array and `offs` is the distance between the start
275275
/// of each element in the array.
276276
///
277-
/// On arithmetic overflow, returns `LayoutErr`.
277+
/// On arithmetic overflow, returns `LayoutError`.
278278
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
279279
#[inline]
280-
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutErr> {
280+
pub fn repeat(&self, n: usize) -> Result<(Self, usize), LayoutError> {
281281
// This cannot overflow. Quoting from the invariant of Layout:
282282
// > `size`, when rounded up to the nearest multiple of `align`,
283283
// > must not overflow (i.e., the rounded value must be less than
284284
// > `usize::MAX`)
285285
let padded_size = self.size() + self.padding_needed_for(self.align());
286-
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutErr { private: () })?;
286+
let alloc_size = padded_size.checked_mul(n).ok_or(LayoutError { private: () })?;
287287

288288
// SAFETY: self.align is already known to be valid and alloc_size has been
289289
// padded already.
@@ -307,16 +307,16 @@ impl Layout {
307307
/// start of the `next` embedded within the concatenated record
308308
/// (assuming that the record itself starts at offset 0).
309309
///
310-
/// On arithmetic overflow, returns `LayoutErr`.
310+
/// On arithmetic overflow, returns `LayoutError`.
311311
///
312312
/// # Examples
313313
///
314314
/// To calculate the layout of a `#[repr(C)]` structure and the offsets of
315315
/// the fields from its fields' layouts:
316316
///
317317
/// ```rust
318-
/// # use std::alloc::{Layout, LayoutErr};
319-
/// pub fn repr_c(fields: &[Layout]) -> Result<(Layout, Vec<usize>), LayoutErr> {
318+
/// # use std::alloc::{Layout, LayoutError};
319+
/// pub fn repr_c(fields: &[Layout]) -> Result<(Layout, Vec<usize>), LayoutError> {
320320
/// let mut offsets = Vec::new();
321321
/// let mut layout = Layout::from_size_align(0, 1)?;
322322
/// for &field in fields {
@@ -337,12 +337,12 @@ impl Layout {
337337
/// ```
338338
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
339339
#[inline]
340-
pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutErr> {
340+
pub fn extend(&self, next: Self) -> Result<(Self, usize), LayoutError> {
341341
let new_align = cmp::max(self.align(), next.align());
342342
let pad = self.padding_needed_for(next.align());
343343

344-
let offset = self.size().checked_add(pad).ok_or(LayoutErr { private: () })?;
345-
let new_size = offset.checked_add(next.size()).ok_or(LayoutErr { private: () })?;
344+
let offset = self.size().checked_add(pad).ok_or(LayoutError { private: () })?;
345+
let new_size = offset.checked_add(next.size()).ok_or(LayoutError { private: () })?;
346346

347347
let layout = Layout::from_size_align(new_size, new_align)?;
348348
Ok((layout, offset))
@@ -359,11 +359,11 @@ impl Layout {
359359
/// guaranteed that all elements in the array will be properly
360360
/// aligned.
361361
///
362-
/// On arithmetic overflow, returns `LayoutErr`.
362+
/// On arithmetic overflow, returns `LayoutError`.
363363
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
364364
#[inline]
365-
pub fn repeat_packed(&self, n: usize) -> Result<Self, LayoutErr> {
366-
let size = self.size().checked_mul(n).ok_or(LayoutErr { private: () })?;
365+
pub fn repeat_packed(&self, n: usize) -> Result<Self, LayoutError> {
366+
let size = self.size().checked_mul(n).ok_or(LayoutError { private: () })?;
367367
Layout::from_size_align(size, self.align())
368368
}
369369

@@ -372,38 +372,41 @@ impl Layout {
372372
/// padding is inserted, the alignment of `next` is irrelevant,
373373
/// and is not incorporated *at all* into the resulting layout.
374374
///
375-
/// On arithmetic overflow, returns `LayoutErr`.
375+
/// On arithmetic overflow, returns `LayoutError`.
376376
#[unstable(feature = "alloc_layout_extra", issue = "55724")]
377377
#[inline]
378-
pub fn extend_packed(&self, next: Self) -> Result<Self, LayoutErr> {
379-
let new_size = self.size().checked_add(next.size()).ok_or(LayoutErr { private: () })?;
378+
pub fn extend_packed(&self, next: Self) -> Result<Self, LayoutError> {
379+
let new_size = self.size().checked_add(next.size()).ok_or(LayoutError { private: () })?;
380380
Layout::from_size_align(new_size, self.align())
381381
}
382382

383383
/// Creates a layout describing the record for a `[T; n]`.
384384
///
385-
/// On arithmetic overflow, returns `LayoutErr`.
385+
/// On arithmetic overflow, returns `LayoutError`.
386386
#[stable(feature = "alloc_layout_manipulation", since = "1.44.0")]
387387
#[inline]
388-
pub fn array<T>(n: usize) -> Result<Self, LayoutErr> {
388+
pub fn array<T>(n: usize) -> Result<Self, LayoutError> {
389389
let (layout, offset) = Layout::new::<T>().repeat(n)?;
390390
debug_assert_eq!(offset, mem::size_of::<T>());
391391
Ok(layout.pad_to_align())
392392
}
393393
}
394394

395+
#[stable(feature = "alloc_layout", since = "1.28.0")]
396+
pub type LayoutErr = LayoutError;
397+
395398
/// The parameters given to `Layout::from_size_align`
396399
/// or some other `Layout` constructor
397400
/// do not satisfy its documented constraints.
398-
#[stable(feature = "alloc_layout", since = "1.28.0")]
401+
#[stable(feature = "alloc_layout_error", since = "1.49.0")]
399402
#[derive(Clone, PartialEq, Eq, Debug)]
400-
pub struct LayoutErr {
403+
pub struct LayoutError {
401404
private: (),
402405
}
403406

404407
// (we need this for downstream impl of trait Error)
405408
#[stable(feature = "alloc_layout", since = "1.28.0")]
406-
impl fmt::Display for LayoutErr {
409+
impl fmt::Display for LayoutError {
407410
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
408411
f.write_str("invalid parameters to Layout::from_size_align")
409412
}

library/core/src/alloc/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ pub use self::global::GlobalAlloc;
1010
#[stable(feature = "alloc_layout", since = "1.28.0")]
1111
pub use self::layout::{Layout, LayoutErr};
1212

13+
#[stable(feature = "alloc_layout_error", since = "1.49.0")]
14+
pub use self::layout::LayoutError;
15+
1316
use crate::fmt;
1417
use crate::ptr::{self, NonNull};
1518

0 commit comments

Comments
 (0)