File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -141,10 +141,10 @@ impl<T> Box<T> {
141
141
/// ```
142
142
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
143
143
pub fn new_uninit ( ) -> Box < mem:: MaybeUninit < T > > {
144
- if mem:: size_of :: < T > ( ) == 0 {
144
+ let layout = alloc:: Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
145
+ if layout. size ( ) == 0 {
145
146
return Box ( NonNull :: dangling ( ) . into ( ) )
146
147
}
147
- let layout = alloc:: Layout :: new :: < mem:: MaybeUninit < T > > ( ) ;
148
148
let ptr = unsafe {
149
149
Global . alloc ( layout)
150
150
. unwrap_or_else ( |_| alloc:: handle_alloc_error ( layout) )
@@ -184,10 +184,10 @@ impl<T> Box<[T]> {
184
184
/// ```
185
185
#[ unstable( feature = "new_uninit" , issue = "63291" ) ]
186
186
pub fn new_uninit_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
187
- let ptr = if mem:: size_of :: < T > ( ) == 0 || len == 0 {
187
+ let layout = alloc:: Layout :: array :: < mem:: MaybeUninit < T > > ( len) . unwrap ( ) ;
188
+ let ptr = if layout. size ( ) == 0 {
188
189
NonNull :: dangling ( )
189
190
} else {
190
- let layout = alloc:: Layout :: array :: < mem:: MaybeUninit < T > > ( len) . unwrap ( ) ;
191
191
unsafe {
192
192
Global . alloc ( layout)
193
193
. unwrap_or_else ( |_| alloc:: handle_alloc_error ( layout) )
You can’t perform that action at this time.
0 commit comments