@@ -328,7 +328,7 @@ pub unsafe trait Allocator {
328
328
#[ must_use] // Doesn't actually work
329
329
type Result < T , E : Error >
330
330
where
331
- E : IntoLayout ;
331
+ E : HandleAllocError ;
332
332
333
333
/// Function to map allocation results into `Self::Result`.
334
334
///
@@ -338,7 +338,7 @@ pub unsafe trait Allocator {
338
338
#[ must_use]
339
339
fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E >
340
340
where
341
- E : IntoLayout ;
341
+ E : HandleAllocError ;
342
342
343
343
/// Result type returned by functions that are conditionally fallible.
344
344
///
@@ -414,12 +414,12 @@ where
414
414
#[ cfg( not( no_global_oom_handling) ) ]
415
415
type Result < T , E : Error > = A :: Result < T , E >
416
416
where
417
- E : IntoLayout ;
417
+ E : HandleAllocError ;
418
418
419
419
#[ cfg( not( no_global_oom_handling) ) ]
420
420
fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E >
421
421
where
422
- E : IntoLayout ,
422
+ E : HandleAllocError ,
423
423
{
424
424
A :: map_result ( result)
425
425
}
@@ -445,22 +445,22 @@ pub(crate) fn capacity_overflow() -> ! {
445
445
panic ! ( "capacity overflow" ) ;
446
446
}
447
447
448
- /// Trait for converting an error into a `Layout` struct,
449
- /// used for passing the layout to [`handle_alloc_error`] .
448
+ /// Trait for handling alloc errors for allocators which
449
+ /// panic or abort instead of returning errors .
450
450
#[ cfg( not( no_global_oom_handling) ) ]
451
451
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
452
- pub trait IntoLayout {
453
- /// Convert into a `Layout` struct.
454
- fn into_layout ( self ) -> Layout ;
452
+ pub trait HandleAllocError {
453
+ /// Globally handle this allocation error, using [`handle_alloc_error`]
454
+ fn handle_alloc_error ( self ) -> ! ;
455
455
}
456
456
457
457
#[ cfg( not( no_global_oom_handling) ) ]
458
458
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
459
- impl IntoLayout for TryReserveError {
460
- fn into_layout ( self ) -> Layout {
459
+ impl HandleAllocError for TryReserveError {
460
+ fn handle_alloc_error ( self ) -> ! {
461
461
match self . kind ( ) {
462
462
TryReserveErrorKind :: CapacityOverflow => capacity_overflow ( ) ,
463
- TryReserveErrorKind :: AllocError { layout, .. } => layout,
463
+ TryReserveErrorKind :: AllocError { layout, .. } => handle_alloc_error ( layout) ,
464
464
}
465
465
}
466
466
}
@@ -535,13 +535,13 @@ where
535
535
536
536
type Result < T , E : Error > = T
537
537
where
538
- E : IntoLayout ;
538
+ E : HandleAllocError ;
539
539
540
540
fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E >
541
541
where
542
- E : IntoLayout ,
542
+ E : HandleAllocError ,
543
543
{
544
- result. unwrap_or_else ( |e| handle_alloc_error ( e . into_layout ( ) ) )
544
+ result. unwrap_or_else ( |e| e . handle_alloc_error ( ) )
545
545
}
546
546
}
547
547
@@ -624,12 +624,12 @@ where
624
624
#[ cfg( not( no_global_oom_handling) ) ]
625
625
type Result < T , E : Error > = Result < T , E >
626
626
where
627
- E : IntoLayout ;
627
+ E : HandleAllocError ;
628
628
629
629
#[ cfg( not( no_global_oom_handling) ) ]
630
630
fn map_result < T , E : Error > ( result : Result < T , E > ) -> Self :: Result < T , E >
631
631
where
632
- E : IntoLayout ,
632
+ E : HandleAllocError ,
633
633
{
634
634
result
635
635
}
0 commit comments