@@ -39,7 +39,7 @@ pub struct Layout {
39
39
40
40
impl Layout {
41
41
/// 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
43
43
/// are not met:
44
44
///
45
45
/// * `align` must not be zero,
@@ -52,9 +52,9 @@ impl Layout {
52
52
#[ stable( feature = "alloc_layout" , since = "1.28.0" ) ]
53
53
#[ rustc_const_unstable( feature = "const_alloc_layout" , issue = "67521" ) ]
54
54
#[ 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 > {
56
56
if !align. is_power_of_two ( ) {
57
- return Err ( LayoutErr { private : ( ) } ) ;
57
+ return Err ( LayoutError { private : ( ) } ) ;
58
58
}
59
59
60
60
// (power-of-two implies align != 0.)
@@ -72,7 +72,7 @@ impl Layout {
72
72
// Above implies that checking for summation overflow is both
73
73
// necessary and sufficient.
74
74
if size > usize:: MAX - ( align - 1 ) {
75
- return Err ( LayoutErr { private : ( ) } ) ;
75
+ return Err ( LayoutError { private : ( ) } ) ;
76
76
}
77
77
78
78
// SAFETY: the conditions for `from_size_align_unchecked` have been
@@ -200,7 +200,7 @@ impl Layout {
200
200
/// `align` violates the conditions listed in [`Layout::from_size_align`].
201
201
#[ stable( feature = "alloc_layout_manipulation" , since = "1.44.0" ) ]
202
202
#[ inline]
203
- pub fn align_to ( & self , align : usize ) -> Result < Self , LayoutErr > {
203
+ pub fn align_to ( & self , align : usize ) -> Result < Self , LayoutError > {
204
204
Layout :: from_size_align ( self . size ( ) , cmp:: max ( self . align ( ) , align) )
205
205
}
206
206
@@ -274,16 +274,16 @@ impl Layout {
274
274
/// layout of the array and `offs` is the distance between the start
275
275
/// of each element in the array.
276
276
///
277
- /// On arithmetic overflow, returns `LayoutErr `.
277
+ /// On arithmetic overflow, returns `LayoutError `.
278
278
#[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
279
279
#[ inline]
280
- pub fn repeat ( & self , n : usize ) -> Result < ( Self , usize ) , LayoutErr > {
280
+ pub fn repeat ( & self , n : usize ) -> Result < ( Self , usize ) , LayoutError > {
281
281
// This cannot overflow. Quoting from the invariant of Layout:
282
282
// > `size`, when rounded up to the nearest multiple of `align`,
283
283
// > must not overflow (i.e., the rounded value must be less than
284
284
// > `usize::MAX`)
285
285
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 : ( ) } ) ?;
287
287
288
288
// SAFETY: self.align is already known to be valid and alloc_size has been
289
289
// padded already.
@@ -307,16 +307,16 @@ impl Layout {
307
307
/// start of the `next` embedded within the concatenated record
308
308
/// (assuming that the record itself starts at offset 0).
309
309
///
310
- /// On arithmetic overflow, returns `LayoutErr `.
310
+ /// On arithmetic overflow, returns `LayoutError `.
311
311
///
312
312
/// # Examples
313
313
///
314
314
/// To calculate the layout of a `#[repr(C)]` structure and the offsets of
315
315
/// the fields from its fields' layouts:
316
316
///
317
317
/// ```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 > {
320
320
/// let mut offsets = Vec::new();
321
321
/// let mut layout = Layout::from_size_align(0, 1)?;
322
322
/// for &field in fields {
@@ -337,12 +337,12 @@ impl Layout {
337
337
/// ```
338
338
#[ stable( feature = "alloc_layout_manipulation" , since = "1.44.0" ) ]
339
339
#[ inline]
340
- pub fn extend ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
340
+ pub fn extend ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutError > {
341
341
let new_align = cmp:: max ( self . align ( ) , next. align ( ) ) ;
342
342
let pad = self . padding_needed_for ( next. align ( ) ) ;
343
343
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 : ( ) } ) ?;
346
346
347
347
let layout = Layout :: from_size_align ( new_size, new_align) ?;
348
348
Ok ( ( layout, offset) )
@@ -359,11 +359,11 @@ impl Layout {
359
359
/// guaranteed that all elements in the array will be properly
360
360
/// aligned.
361
361
///
362
- /// On arithmetic overflow, returns `LayoutErr `.
362
+ /// On arithmetic overflow, returns `LayoutError `.
363
363
#[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
364
364
#[ 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 : ( ) } ) ?;
367
367
Layout :: from_size_align ( size, self . align ( ) )
368
368
}
369
369
@@ -372,38 +372,46 @@ impl Layout {
372
372
/// padding is inserted, the alignment of `next` is irrelevant,
373
373
/// and is not incorporated *at all* into the resulting layout.
374
374
///
375
- /// On arithmetic overflow, returns `LayoutErr `.
375
+ /// On arithmetic overflow, returns `LayoutError `.
376
376
#[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
377
377
#[ 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 : ( ) } ) ?;
380
380
Layout :: from_size_align ( new_size, self . align ( ) )
381
381
}
382
382
383
383
/// Creates a layout describing the record for a `[T; n]`.
384
384
///
385
- /// On arithmetic overflow, returns `LayoutErr `.
385
+ /// On arithmetic overflow, returns `LayoutError `.
386
386
#[ stable( feature = "alloc_layout_manipulation" , since = "1.44.0" ) ]
387
387
#[ inline]
388
- pub fn array < T > ( n : usize ) -> Result < Self , LayoutErr > {
388
+ pub fn array < T > ( n : usize ) -> Result < Self , LayoutError > {
389
389
let ( layout, offset) = Layout :: new :: < T > ( ) . repeat ( n) ?;
390
390
debug_assert_eq ! ( offset, mem:: size_of:: <T >( ) ) ;
391
391
Ok ( layout. pad_to_align ( ) )
392
392
}
393
393
}
394
394
395
+ #[ stable( feature = "alloc_layout" , since = "1.28.0" ) ]
396
+ #[ rustc_deprecated(
397
+ since = "1.51.0" ,
398
+ reason = "Name does not follow std convention, use LayoutError" ,
399
+ suggestion = "LayoutError"
400
+ ) ]
401
+ pub type LayoutErr = LayoutError ;
402
+
395
403
/// The parameters given to `Layout::from_size_align`
396
404
/// or some other `Layout` constructor
397
405
/// do not satisfy its documented constraints.
398
- #[ stable( feature = "alloc_layout " , since = "1.28 .0" ) ]
406
+ #[ stable( feature = "alloc_layout_error " , since = "1.49 .0" ) ]
399
407
#[ derive( Clone , PartialEq , Eq , Debug ) ]
400
- pub struct LayoutErr {
408
+ pub struct LayoutError {
401
409
private : ( ) ,
402
410
}
403
411
404
412
// (we need this for downstream impl of trait Error)
405
413
#[ stable( feature = "alloc_layout" , since = "1.28.0" ) ]
406
- impl fmt:: Display for LayoutErr {
414
+ impl fmt:: Display for LayoutError {
407
415
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
408
416
f. write_str ( "invalid parameters to Layout::from_size_align" )
409
417
}
0 commit comments