File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -213,16 +213,18 @@ impl Layout {
213
213
/// Creates a layout by rounding the size of this layout up to a multiple
214
214
/// of the layout's alignment.
215
215
///
216
- /// Returns `Err` if the padded size would overflow.
217
- ///
218
216
/// This is equivalent to adding the result of `padding_needed_for`
219
217
/// to the layout's current size.
220
218
#[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
221
219
#[ inline]
222
- pub fn pad_to_align ( & self ) -> Result < Layout , LayoutErr > {
220
+ pub fn pad_to_align ( & self ) -> Layout {
223
221
let pad = self . padding_needed_for ( self . align ( ) ) ;
224
- let new_size = self . size ( ) . checked_add ( pad)
225
- . ok_or ( LayoutErr { private : ( ) } ) ?;
222
+ // This cannot overflow: it is an invariant of Layout that
223
+ // > `size`, when rounded up to the nearest multiple of `align`,
224
+ // > must not overflow (i.e., the rounded value must be less than
225
+ // > `usize::MAX`)
226
+ let new_size = self . size ( ) + pad;
227
+ debug_assert ! ( new_size > self . size( ) ) ;
226
228
227
229
Layout :: from_size_align ( new_size, self . align ( ) )
228
230
}
You can’t perform that action at this time.
0 commit comments