@@ -164,15 +164,13 @@ impl Layout {
164
164
/// alignment. In other words, if `K` has size 16, `K.align_to(32)`
165
165
/// will *still* have size 16.
166
166
///
167
- /// # Panics
168
- ///
169
- /// Panics if the combination of `self.size()` and the given `align`
170
- /// violates the conditions listed in
167
+ /// Returns an error if the combination of `self.size()` and the given
168
+ /// `align` violates the conditions listed in
171
169
/// [`Layout::from_size_align`](#method.from_size_align).
172
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
170
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
173
171
#[ inline]
174
- pub fn align_to ( & self , align : usize ) -> Self {
175
- Layout :: from_size_align ( self . size ( ) , cmp:: max ( self . align ( ) , align) ) . unwrap ( )
172
+ pub fn align_to ( & self , align : usize ) -> Result < Self , LayoutErr > {
173
+ Layout :: from_size_align ( self . size ( ) , cmp:: max ( self . align ( ) , align) )
176
174
}
177
175
178
176
/// Returns the amount of padding we must insert after `self`
@@ -191,7 +189,7 @@ impl Layout {
191
189
/// to be less than or equal to the alignment of the starting
192
190
/// address for the whole allocated block of memory. One way to
193
191
/// satisfy this constraint is to ensure `align <= self.align()`.
194
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
192
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
195
193
#[ inline]
196
194
pub fn padding_needed_for ( & self , align : usize ) -> usize {
197
195
let len = self . size ( ) ;
@@ -228,7 +226,7 @@ impl Layout {
228
226
/// of each element in the array.
229
227
///
230
228
/// On arithmetic overflow, returns `LayoutErr`.
231
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
229
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
232
230
#[ inline]
233
231
pub fn repeat ( & self , n : usize ) -> Result < ( Self , usize ) , LayoutErr > {
234
232
let padded_size = self . size ( ) . checked_add ( self . padding_needed_for ( self . align ( ) ) )
@@ -248,13 +246,16 @@ impl Layout {
248
246
/// will be properly aligned. Note that the result layout will
249
247
/// satisfy the alignment properties of both `self` and `next`.
250
248
///
249
+ /// The resulting layout will be the same as that of a C struct containing
250
+ /// two fields with the layouts of `self` and `next`, in that order.
251
+ ///
251
252
/// Returns `Some((k, offset))`, where `k` is layout of the concatenated
252
253
/// record and `offset` is the relative location, in bytes, of the
253
254
/// start of the `next` embedded within the concatenated record
254
255
/// (assuming that the record itself starts at offset 0).
255
256
///
256
257
/// On arithmetic overflow, returns `LayoutErr`.
257
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
258
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
258
259
#[ inline]
259
260
pub fn extend ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
260
261
let new_align = cmp:: max ( self . align ( ) , next. align ( ) ) ;
@@ -281,7 +282,7 @@ impl Layout {
281
282
/// aligned.
282
283
///
283
284
/// On arithmetic overflow, returns `LayoutErr`.
284
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
285
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
285
286
#[ inline]
286
287
pub fn repeat_packed ( & self , n : usize ) -> Result < Self , LayoutErr > {
287
288
let size = self . size ( ) . checked_mul ( n) . ok_or ( LayoutErr { private : ( ) } ) ?;
@@ -293,29 +294,20 @@ impl Layout {
293
294
/// padding is inserted, the alignment of `next` is irrelevant,
294
295
/// and is not incorporated *at all* into the resulting layout.
295
296
///
296
- /// Returns `(k, offset)`, where `k` is layout of the concatenated
297
- /// record and `offset` is the relative location, in bytes, of the
298
- /// start of the `next` embedded within the concatenated record
299
- /// (assuming that the record itself starts at offset 0).
300
- ///
301
- /// (The `offset` is always the same as `self.size()`; we use this
302
- /// signature out of convenience in matching the signature of
303
- /// `extend`.)
304
- ///
305
297
/// On arithmetic overflow, returns `LayoutErr`.
306
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
298
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
307
299
#[ inline]
308
- pub fn extend_packed ( & self , next : Self ) -> Result < ( Self , usize ) , LayoutErr > {
300
+ pub fn extend_packed ( & self , next : Self ) -> Result < Self , LayoutErr > {
309
301
let new_size = self . size ( ) . checked_add ( next. size ( ) )
310
302
. ok_or ( LayoutErr { private : ( ) } ) ?;
311
303
let layout = Layout :: from_size_align ( new_size, self . align ( ) ) ?;
312
- Ok ( ( layout, self . size ( ) ) )
304
+ Ok ( layout)
313
305
}
314
306
315
307
/// Creates a layout describing the record for a `[T; n]`.
316
308
///
317
309
/// On arithmetic overflow, returns `LayoutErr`.
318
- #[ unstable( feature = "allocator_api " , issue = "32838 " ) ]
310
+ #[ unstable( feature = "alloc_layout_extra " , issue = "55724 " ) ]
319
311
#[ inline]
320
312
pub fn array < T > ( n : usize ) -> Result < Self , LayoutErr > {
321
313
Layout :: new :: < T > ( )
0 commit comments