File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -239,8 +239,11 @@ impl Layout {
239239 #[ unstable( feature = "alloc_layout_extra" , issue = "55724" ) ]
240240 #[ inline]
241241 pub fn repeat ( & self , n : usize ) -> Result < ( Self , usize ) , LayoutErr > {
242- let padded_size = self . size ( ) . checked_add ( self . padding_needed_for ( self . align ( ) ) )
243- . ok_or ( LayoutErr { private : ( ) } ) ?;
242+ // This cannot overflow. Quoting from the invariant of Layout:
243+ // > `size`, when rounded up to the nearest multiple of `align`,
244+ // > must not overflow (i.e., the rounded value must be less than
245+ // > `usize::MAX`)
246+ let padded_size = self . size ( ) + self . padding_needed_for ( self . align ( ) ) ;
244247 let alloc_size = padded_size. checked_mul ( n)
245248 . ok_or ( LayoutErr { private : ( ) } ) ?;
246249
You can’t perform that action at this time.
0 commit comments