7979//! [`NonZeroLayout::for_value(&*value)`]: crate::alloc::NonZeroLayout::for_value
8080
8181use crate :: {
82- alloc:: { AllocRef , BuildAllocRef , DeallocRef , Global , NonZeroLayout } ,
82+ alloc:: { AbortAlloc , AllocRef , BuildAllocRef , DeallocRef , Global , NonZeroLayout } ,
8383 clone:: CloneIn ,
8484 collections:: CollectionAllocErr ,
8585 raw_vec:: RawVec ,
@@ -105,7 +105,7 @@ use core::{
105105/// A pointer type for heap allocation.
106106///
107107/// 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 > > {
109109 ptr : Unique < T > ,
110110 build_alloc : A :: BuildAlloc ,
111111}
@@ -131,7 +131,7 @@ impl<T> Box<T> {
131131 #[ inline( always) ]
132132 #[ must_use]
133133 pub fn new ( x : T ) -> Self {
134- Self :: new_in ( x, Global )
134+ Self :: new_in ( x, AbortAlloc ( Global ) )
135135 }
136136
137137 /// Constructs a new box with uninitialized contents.
@@ -156,7 +156,7 @@ impl<T> Box<T> {
156156 #[ inline( always) ]
157157 #[ must_use]
158158 pub fn new_uninit ( ) -> Box < mem:: MaybeUninit < T > > {
159- Self :: new_uninit_in ( Global )
159+ Self :: new_uninit_in ( AbortAlloc ( Global ) )
160160 }
161161
162162 /// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
@@ -177,14 +177,20 @@ impl<T, A: AllocRef> Box<T, A> {
177177 /// # Example
178178 ///
179179 /// ```
180- /// use alloc_wg::{alloc::Global, boxed::Box};
180+ /// use alloc_wg::{
181+ /// alloc::{AbortAlloc, Global},
182+ /// boxed::Box,
183+ /// };
181184 ///
182185 /// # #[allow(unused_variables)]
183- /// let five = Box::new_in(5, Global);
186+ /// let five = Box::new_in(5, AbortAlloc( Global) );
184187 /// ```
185188 #[ allow( clippy:: inline_always) ]
186189 #[ 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+ {
188194 unsafe { Self :: try_new_in ( x, a) . unwrap_unchecked ( ) }
189195 }
190196
@@ -219,9 +225,12 @@ impl<T, A: AllocRef> Box<T, A> {
219225 /// # Example
220226 ///
221227 /// ```
222- /// use alloc_wg::{alloc::Global, boxed::Box};
228+ /// use alloc_wg::{
229+ /// alloc::{AbortAlloc, Global},
230+ /// boxed::Box,
231+ /// };
223232 ///
224- /// let mut five = Box::<u32, _>::new_uninit_in(Global);
233+ /// let mut five = Box::<u32, _>::new_uninit_in(AbortAlloc( Global) );
225234 ///
226235 /// let five = unsafe {
227236 /// // Deferred initialization:
@@ -234,7 +243,10 @@ impl<T, A: AllocRef> Box<T, A> {
234243 /// ```
235244 #[ allow( clippy:: inline_always) ]
236245 #[ 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+ {
238250 unsafe { Self :: try_new_uninit_in ( a) . unwrap_unchecked ( ) }
239251 }
240252
@@ -271,7 +283,10 @@ impl<T, A: AllocRef> Box<T, A> {
271283 /// `Unpin`, then `x` will be pinned in memory and unable to be moved.
272284 #[ allow( clippy:: inline_always) ]
273285 #[ 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+ {
275290 unsafe { Self :: try_pin_in ( x, a) . unwrap_unchecked ( ) }
276291 }
277292
@@ -309,7 +324,7 @@ impl<T> Box<[T]> {
309324 #[ inline( always) ]
310325 #[ must_use]
311326 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 ) )
313328 }
314329}
315330
@@ -320,9 +335,12 @@ impl<T, A: AllocRef> Box<[T], A> {
320335 /// # Example
321336 ///
322337 /// ```
323- /// use alloc_wg::{alloc::Global, boxed::Box};
338+ /// use alloc_wg::{
339+ /// alloc::{AbortAlloc, Global},
340+ /// boxed::Box,
341+ /// };
324342 ///
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) );
326344 ///
327345 /// let values = unsafe {
328346 /// // Deferred initialization:
@@ -337,7 +355,10 @@ impl<T, A: AllocRef> Box<[T], A> {
337355 /// ```
338356 #[ allow( clippy:: inline_always) ]
339357 #[ 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+ {
341362 unsafe { Self :: try_new_uninit_slice_in ( len, a) . unwrap_unchecked ( ) }
342363 }
343364
@@ -503,7 +524,7 @@ impl<T: ?Sized> Box<T> {
503524 #[ allow( clippy:: inline_always) ]
504525 #[ inline( always) ]
505526 pub unsafe fn from_raw ( raw : * mut T ) -> Self {
506- Self :: from_raw_in ( raw, Global )
527+ Self :: from_raw_in ( raw, AbortAlloc ( Global ) )
507528 }
508529}
509530
@@ -747,7 +768,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: DeallocRef> Drop for Box<T, A> {
747768impl < T , A > Default for Box < T , A >
748769where
749770 T : Default ,
750- A : Default + AllocRef ,
771+ A : Default + AllocRef < Error = ! > ,
751772{
752773 #[ must_use]
753774 fn default ( ) -> Self {
@@ -758,7 +779,7 @@ where
758779#[ allow( clippy:: use_self) ]
759780impl < T , A > Default for Box < [ T ] , A >
760781where
761- A : Default + AllocRef ,
782+ A : Default + AllocRef < Error = ! > ,
762783{
763784 #[ must_use]
764785 fn default ( ) -> Self {
@@ -775,7 +796,7 @@ unsafe fn from_boxed_utf8_unchecked<A: DeallocRef>(v: Box<[u8], A>) -> Box<str,
775796#[ allow( clippy:: use_self) ]
776797impl < A > Default for Box < str , A >
777798where
778- A : Default + AllocRef ,
799+ A : Default + AllocRef < Error = ! > ,
779800{
780801 #[ must_use]
781802 fn default ( ) -> Self {
@@ -785,7 +806,7 @@ where
785806
786807impl < T : Clone , A > Clone for Box < T , A >
787808where
788- A : AllocRef ,
809+ A : AllocRef < Error = ! > ,
789810 A :: BuildAlloc : Clone ,
790811{
791812 /// Returns a new box with a `clone()` of this box's contents.
@@ -846,7 +867,10 @@ where
846867impl < T : Clone , A : AllocRef , B : AllocRef > CloneIn < B > for Box < T , A > {
847868 type Cloned = Box < T , B > ;
848869
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+ {
850874 Box :: new_in ( self . as_ref ( ) . clone ( ) , a)
851875 }
852876
@@ -949,7 +973,7 @@ impl<T: ?Sized + Hasher, A: DeallocRef> Hasher for Box<T, A> {
949973
950974impl < T , A > From < T > for Box < T , A >
951975where
952- A : Default + AllocRef ,
976+ A : Default + AllocRef < Error = ! > ,
953977{
954978 /// Converts a generic type `T` into a `Box<T>`
955979 ///
@@ -983,7 +1007,7 @@ impl<T: ?Sized, A: DeallocRef> From<Box<T, A>> for Pin<Box<T, A>> {
9831007#[ allow( clippy:: use_self) ]
9841008impl < T : Copy , A > From < & [ T ] > for Box < [ T ] , A >
9851009where
986- A : Default + AllocRef ,
1010+ A : Default + AllocRef < Error = ! > ,
9871011{
9881012 /// Converts a `&[T]` into a `Box<[T], B>`
9891013 ///
@@ -1012,7 +1036,7 @@ where
10121036#[ allow( clippy:: use_self) ]
10131037impl < A > From < & str > for Box < str , A >
10141038where
1015- A : Default + AllocRef ,
1039+ A : Default + AllocRef < Error = ! > ,
10161040{
10171041 /// Converts a `&str` into a `Box<str>`
10181042 ///
@@ -1266,13 +1290,16 @@ macro_rules! impl_dispatch_from_dyn {
12661290}
12671291
12681292impl_dispatch_from_dyn ! ( Global ) ;
1293+ impl_dispatch_from_dyn ! ( AbortAlloc <Global >) ;
12691294#[ cfg( feature = "std" ) ]
12701295impl_dispatch_from_dyn ! ( std:: alloc:: System ) ;
1296+ #[ cfg( feature = "std" ) ]
1297+ impl_dispatch_from_dyn ! ( AbortAlloc <std:: alloc:: System >) ;
12711298
12721299#[ allow( clippy:: items_after_statements) ]
12731300impl < T : Clone , A : Clone > Clone for Box < [ T ] , A >
12741301where
1275- A : AllocRef ,
1302+ A : AllocRef < Error = ! > ,
12761303 A :: BuildAlloc : Clone ,
12771304{
12781305 fn clone ( & self ) -> Self {
0 commit comments