79
79
//! [`NonZeroLayout::for_value(&*value)`]: crate::alloc::NonZeroLayout::for_value
80
80
81
81
use crate :: {
82
- alloc:: { AllocRef , BuildAllocRef , DeallocRef , Global , NonZeroLayout } ,
82
+ alloc:: { AbortAlloc , AllocRef , BuildAllocRef , DeallocRef , Global , NonZeroLayout } ,
83
83
clone:: CloneIn ,
84
84
collections:: CollectionAllocErr ,
85
85
raw_vec:: RawVec ,
@@ -105,7 +105,7 @@ use core::{
105
105
/// A pointer type for heap allocation.
106
106
///
107
107
/// See the [module-level documentation](index.html) for more.
108
- pub struct Box < T : ?Sized , A : DeallocRef = Global > {
108
+ pub struct Box < T : ?Sized , A : DeallocRef = AbortAlloc < Global > > {
109
109
ptr : Unique < T > ,
110
110
build_alloc : A :: BuildAlloc ,
111
111
}
@@ -131,7 +131,7 @@ impl<T> Box<T> {
131
131
#[ inline( always) ]
132
132
#[ must_use]
133
133
pub fn new ( x : T ) -> Self {
134
- Self :: new_in ( x, Global )
134
+ Self :: new_in ( x, AbortAlloc ( Global ) )
135
135
}
136
136
137
137
/// Constructs a new box with uninitialized contents.
@@ -156,7 +156,7 @@ impl<T> Box<T> {
156
156
#[ inline( always) ]
157
157
#[ must_use]
158
158
pub fn new_uninit ( ) -> Box < mem:: MaybeUninit < T > > {
159
- Self :: new_uninit_in ( Global )
159
+ Self :: new_uninit_in ( AbortAlloc ( Global ) )
160
160
}
161
161
162
162
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
@@ -177,14 +177,20 @@ impl<T, A: AllocRef> Box<T, A> {
177
177
/// # Example
178
178
///
179
179
/// ```
180
- /// use alloc_wg::{alloc::Global, boxed::Box};
180
+ /// use alloc_wg::{
181
+ /// alloc::{AbortAlloc, Global},
182
+ /// boxed::Box,
183
+ /// };
181
184
///
182
185
/// # #[allow(unused_variables)]
183
- /// let five = Box::new_in(5, Global);
186
+ /// let five = Box::new_in(5, AbortAlloc( Global) );
184
187
/// ```
185
188
#[ allow( clippy:: inline_always) ]
186
189
#[ inline( always) ]
187
- pub fn new_in ( x : T , a : A ) -> Self {
190
+ pub fn new_in ( x : T , a : A ) -> Self
191
+ where
192
+ A : AllocRef < Error = !> ,
193
+ {
188
194
unsafe { Self :: try_new_in ( x, a) . unwrap_unchecked ( ) }
189
195
}
190
196
@@ -219,9 +225,12 @@ impl<T, A: AllocRef> Box<T, A> {
219
225
/// # Example
220
226
///
221
227
/// ```
222
- /// use alloc_wg::{alloc::Global, boxed::Box};
228
+ /// use alloc_wg::{
229
+ /// alloc::{AbortAlloc, Global},
230
+ /// boxed::Box,
231
+ /// };
223
232
///
224
- /// let mut five = Box::<u32, _>::new_uninit_in(Global);
233
+ /// let mut five = Box::<u32, _>::new_uninit_in(AbortAlloc( Global) );
225
234
///
226
235
/// let five = unsafe {
227
236
/// // Deferred initialization:
@@ -234,7 +243,10 @@ impl<T, A: AllocRef> Box<T, A> {
234
243
/// ```
235
244
#[ allow( clippy:: inline_always) ]
236
245
#[ inline( always) ]
237
- pub fn new_uninit_in ( a : A ) -> Box < mem:: MaybeUninit < T > , A > {
246
+ pub fn new_uninit_in ( a : A ) -> Box < mem:: MaybeUninit < T > , A >
247
+ where
248
+ A : AllocRef < Error = !> ,
249
+ {
238
250
unsafe { Self :: try_new_uninit_in ( a) . unwrap_unchecked ( ) }
239
251
}
240
252
@@ -271,7 +283,10 @@ impl<T, A: AllocRef> Box<T, A> {
271
283
/// `Unpin`, then `x` will be pinned in memory and unable to be moved.
272
284
#[ allow( clippy:: inline_always) ]
273
285
#[ inline( always) ]
274
- pub fn pin_in ( x : T , a : A ) -> Pin < Self > {
286
+ pub fn pin_in ( x : T , a : A ) -> Pin < Self >
287
+ where
288
+ A : AllocRef < Error = !> ,
289
+ {
275
290
unsafe { Self :: try_pin_in ( x, a) . unwrap_unchecked ( ) }
276
291
}
277
292
@@ -309,7 +324,7 @@ impl<T> Box<[T]> {
309
324
#[ inline( always) ]
310
325
#[ must_use]
311
326
pub fn new_uninit_slice ( len : usize ) -> Box < [ mem:: MaybeUninit < T > ] > {
312
- Self :: new_uninit_slice_in ( len, Global )
327
+ Self :: new_uninit_slice_in ( len, AbortAlloc ( Global ) )
313
328
}
314
329
}
315
330
@@ -320,9 +335,12 @@ impl<T, A: AllocRef> Box<[T], A> {
320
335
/// # Example
321
336
///
322
337
/// ```
323
- /// use alloc_wg::{alloc::Global, boxed::Box};
338
+ /// use alloc_wg::{
339
+ /// alloc::{AbortAlloc, Global},
340
+ /// boxed::Box,
341
+ /// };
324
342
///
325
- /// let mut values = Box::<[u32], _> ::new_uninit_slice_in(3, Global);
343
+ /// let mut values = Box::<[u32], AbortAlloc<Global>> ::new_uninit_slice_in(3, AbortAlloc( Global) );
326
344
///
327
345
/// let values = unsafe {
328
346
/// // Deferred initialization:
@@ -337,7 +355,10 @@ impl<T, A: AllocRef> Box<[T], A> {
337
355
/// ```
338
356
#[ allow( clippy:: inline_always) ]
339
357
#[ inline( always) ]
340
- pub fn new_uninit_slice_in ( len : usize , a : A ) -> Box < [ mem:: MaybeUninit < T > ] , A > {
358
+ pub fn new_uninit_slice_in ( len : usize , a : A ) -> Box < [ mem:: MaybeUninit < T > ] , A >
359
+ where
360
+ A : AllocRef < Error = !> ,
361
+ {
341
362
unsafe { Self :: try_new_uninit_slice_in ( len, a) . unwrap_unchecked ( ) }
342
363
}
343
364
@@ -503,7 +524,7 @@ impl<T: ?Sized> Box<T> {
503
524
#[ allow( clippy:: inline_always) ]
504
525
#[ inline( always) ]
505
526
pub unsafe fn from_raw ( raw : * mut T ) -> Self {
506
- Self :: from_raw_in ( raw, Global )
527
+ Self :: from_raw_in ( raw, AbortAlloc ( Global ) )
507
528
}
508
529
}
509
530
@@ -747,7 +768,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: DeallocRef> Drop for Box<T, A> {
747
768
impl < T , A > Default for Box < T , A >
748
769
where
749
770
T : Default ,
750
- A : Default + AllocRef ,
771
+ A : Default + AllocRef < Error = ! > ,
751
772
{
752
773
#[ must_use]
753
774
fn default ( ) -> Self {
@@ -758,7 +779,7 @@ where
758
779
#[ allow( clippy:: use_self) ]
759
780
impl < T , A > Default for Box < [ T ] , A >
760
781
where
761
- A : Default + AllocRef ,
782
+ A : Default + AllocRef < Error = ! > ,
762
783
{
763
784
#[ must_use]
764
785
fn default ( ) -> Self {
@@ -775,7 +796,7 @@ unsafe fn from_boxed_utf8_unchecked<A: DeallocRef>(v: Box<[u8], A>) -> Box<str,
775
796
#[ allow( clippy:: use_self) ]
776
797
impl < A > Default for Box < str , A >
777
798
where
778
- A : Default + AllocRef ,
799
+ A : Default + AllocRef < Error = ! > ,
779
800
{
780
801
#[ must_use]
781
802
fn default ( ) -> Self {
@@ -785,7 +806,7 @@ where
785
806
786
807
impl < T : Clone , A > Clone for Box < T , A >
787
808
where
788
- A : AllocRef ,
809
+ A : AllocRef < Error = ! > ,
789
810
A :: BuildAlloc : Clone ,
790
811
{
791
812
/// Returns a new box with a `clone()` of this box's contents.
@@ -846,7 +867,10 @@ where
846
867
impl < T : Clone , A : AllocRef , B : AllocRef > CloneIn < B > for Box < T , A > {
847
868
type Cloned = Box < T , B > ;
848
869
849
- fn clone_in ( & self , a : B ) -> Self :: Cloned {
870
+ fn clone_in ( & self , a : B ) -> Self :: Cloned
871
+ where
872
+ B : AllocRef < Error = !> ,
873
+ {
850
874
Box :: new_in ( self . as_ref ( ) . clone ( ) , a)
851
875
}
852
876
@@ -949,7 +973,7 @@ impl<T: ?Sized + Hasher, A: DeallocRef> Hasher for Box<T, A> {
949
973
950
974
impl < T , A > From < T > for Box < T , A >
951
975
where
952
- A : Default + AllocRef ,
976
+ A : Default + AllocRef < Error = ! > ,
953
977
{
954
978
/// Converts a generic type `T` into a `Box<T>`
955
979
///
@@ -983,7 +1007,7 @@ impl<T: ?Sized, A: DeallocRef> From<Box<T, A>> for Pin<Box<T, A>> {
983
1007
#[ allow( clippy:: use_self) ]
984
1008
impl < T : Copy , A > From < & [ T ] > for Box < [ T ] , A >
985
1009
where
986
- A : Default + AllocRef ,
1010
+ A : Default + AllocRef < Error = ! > ,
987
1011
{
988
1012
/// Converts a `&[T]` into a `Box<[T], B>`
989
1013
///
@@ -1012,7 +1036,7 @@ where
1012
1036
#[ allow( clippy:: use_self) ]
1013
1037
impl < A > From < & str > for Box < str , A >
1014
1038
where
1015
- A : Default + AllocRef ,
1039
+ A : Default + AllocRef < Error = ! > ,
1016
1040
{
1017
1041
/// Converts a `&str` into a `Box<str>`
1018
1042
///
@@ -1266,13 +1290,16 @@ macro_rules! impl_dispatch_from_dyn {
1266
1290
}
1267
1291
1268
1292
impl_dispatch_from_dyn ! ( Global ) ;
1293
+ impl_dispatch_from_dyn ! ( AbortAlloc <Global >) ;
1269
1294
#[ cfg( feature = "std" ) ]
1270
1295
impl_dispatch_from_dyn ! ( std:: alloc:: System ) ;
1296
+ #[ cfg( feature = "std" ) ]
1297
+ impl_dispatch_from_dyn ! ( AbortAlloc <std:: alloc:: System >) ;
1271
1298
1272
1299
#[ allow( clippy:: items_after_statements) ]
1273
1300
impl < T : Clone , A : Clone > Clone for Box < [ T ] , A >
1274
1301
where
1275
- A : AllocRef ,
1302
+ A : AllocRef < Error = ! > ,
1276
1303
A :: BuildAlloc : Clone ,
1277
1304
{
1278
1305
fn clone ( & self ) -> Self {
0 commit comments