File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -213,16 +213,18 @@ impl Layout {
213213 /// Creates a layout by rounding the size of this layout up to a multiple
214214 /// of the layout's alignment.
215215 ///
216- /// Returns `Err` if the padded size would overflow.
217- ///
218216 /// This is equivalent to adding the result of `padding_needed_for`
219217 /// to the layout's current size.
220218 #[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
221219 #[ inline]
222- pub fn pad_to_align ( & self ) -> Result < Layout , LayoutErr > {
220+ pub fn pad_to_align ( & self ) -> Layout {
223221 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( ) ) ;
226228
227229 Layout :: from_size_align ( new_size, self . align ( ) )
228230 }
You can’t perform that action at this time.
0 commit comments