248
248
#![ cfg_attr( any( feature = "alloc" ) , feature( new_uninit) ) ]
249
249
#![ cfg_attr( any( feature = "alloc" ) , feature( get_mut_unchecked) ) ]
250
250
251
- #[ cfg( any ( feature = "alloc" ) ) ]
251
+ #[ cfg( feature = "alloc" ) ]
252
252
extern crate alloc;
253
253
254
- #[ cfg( any( feature = "alloc" ) ) ]
255
- use alloc:: { boxed:: Box , sync:: Arc } ;
254
+ #[ cfg( all( feature = "alloc" , not( feature = "std" ) ) ) ]
255
+ use alloc:: boxed:: Box ;
256
+ #[ cfg( feature = "alloc" ) ]
257
+ use alloc:: sync:: Arc ;
258
+
256
259
use core:: {
257
260
alloc:: AllocError ,
258
261
cell:: UnsafeCell ,
@@ -1202,8 +1205,9 @@ pub trait InPlaceInit<T>: Sized {
1202
1205
fn pin_init ( init : impl PinInit < T > ) -> Result < Pin < Self > , AllocError > {
1203
1206
// SAFETY: We delegate to `init` and only change the error type.
1204
1207
let init = unsafe {
1205
- pin_init_from_closure ( |slot| {
1206
- Ok ( init. __pinned_init ( slot) . unwrap ( ) ) // cannot fail
1208
+ pin_init_from_closure ( |slot| match init. __pinned_init ( slot) {
1209
+ Ok ( ( ) ) => Ok ( ( ) ) ,
1210
+ Err ( i) => match i { } ,
1207
1211
} )
1208
1212
} ;
1209
1213
Self :: try_pin_init ( init)
@@ -1217,13 +1221,16 @@ pub trait InPlaceInit<T>: Sized {
1217
1221
/// Use the given initializer to in-place initialize a `T`.
1218
1222
fn init ( init : impl Init < T > ) -> Result < Self , AllocError > {
1219
1223
let init = unsafe {
1220
- init_from_closure ( |slot| Ok ( init. __init ( slot) . unwrap ( ) ) ) //cannot fail
1224
+ init_from_closure ( |slot| match init. __init ( slot) {
1225
+ Ok ( ( ) ) => Ok ( ( ) ) ,
1226
+ Err ( i) => match i { } ,
1227
+ } )
1221
1228
} ;
1222
1229
Self :: try_init ( init)
1223
1230
}
1224
1231
}
1225
1232
1226
- #[ cfg( any ( feature = "alloc" ) ) ]
1233
+ #[ cfg( feature = "alloc" ) ]
1227
1234
impl < T > InPlaceInit < T > for Box < T > {
1228
1235
#[ inline]
1229
1236
fn try_pin_init < E > ( init : impl PinInit < T , E > ) -> Result < Pin < Self > , E >
@@ -1254,7 +1261,7 @@ impl<T> InPlaceInit<T> for Box<T> {
1254
1261
}
1255
1262
}
1256
1263
1257
- #[ cfg( any ( feature = "alloc" ) ) ]
1264
+ #[ cfg( feature = "alloc" ) ]
1258
1265
impl < T > InPlaceInit < T > for Arc < T > {
1259
1266
#[ inline]
1260
1267
fn try_pin_init < E > ( init : impl PinInit < T , E > ) -> Result < Pin < Self > , E >
0 commit comments