Skip to content

Commit adc0771

Browse files
committed
refactor IntoLayout to HandleAllocError
1 parent dfb32b2 commit adc0771

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

library/alloc/src/alloc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use core::ptr::{self, NonNull};
1616
pub use crate::falloc::{Allocator, FallibleAdapter};
1717
#[unstable(feature = "allocator_api", issue = "32838")]
1818
#[cfg(not(no_global_oom_handling))]
19-
pub use crate::falloc::{InfallibleAdapter, IntoLayout};
19+
pub use crate::falloc::{HandleAllocError, InfallibleAdapter};
2020
#[stable(feature = "alloc_module", since = "1.28.0")]
2121
#[doc(inline)]
2222
#[allow(deprecated)]
@@ -333,14 +333,14 @@ unsafe impl Allocator for Global {
333333
#[cfg(not(no_global_oom_handling))]
334334
type Result<T, E: Error> = T
335335
where
336-
E: IntoLayout;
336+
E: HandleAllocError;
337337

338338
#[cfg(not(no_global_oom_handling))]
339339
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
340340
where
341-
E: IntoLayout,
341+
E: HandleAllocError,
342342
{
343-
result.unwrap_or_else(|e| handle_alloc_error(e.into_layout()))
343+
result.unwrap_or_else(|e| e.handle_alloc_error())
344344
}
345345

346346
#[cfg(no_global_oom_handling)]

library/alloc/src/falloc.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub unsafe trait Allocator {
328328
#[must_use] // Doesn't actually work
329329
type Result<T, E: Error>
330330
where
331-
E: IntoLayout;
331+
E: HandleAllocError;
332332

333333
/// Function to map allocation results into `Self::Result`.
334334
///
@@ -338,7 +338,7 @@ pub unsafe trait Allocator {
338338
#[must_use]
339339
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
340340
where
341-
E: IntoLayout;
341+
E: HandleAllocError;
342342

343343
/// Result type returned by functions that are conditionally fallible.
344344
///
@@ -414,12 +414,12 @@ where
414414
#[cfg(not(no_global_oom_handling))]
415415
type Result<T, E: Error> = A::Result<T, E>
416416
where
417-
E: IntoLayout;
417+
E: HandleAllocError;
418418

419419
#[cfg(not(no_global_oom_handling))]
420420
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
421421
where
422-
E: IntoLayout,
422+
E: HandleAllocError,
423423
{
424424
A::map_result(result)
425425
}
@@ -445,22 +445,22 @@ pub(crate) fn capacity_overflow() -> ! {
445445
panic!("capacity overflow");
446446
}
447447

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.
450450
#[cfg(not(no_global_oom_handling))]
451451
#[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) -> !;
455455
}
456456

457457
#[cfg(not(no_global_oom_handling))]
458458
#[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) -> ! {
461461
match self.kind() {
462462
TryReserveErrorKind::CapacityOverflow => capacity_overflow(),
463-
TryReserveErrorKind::AllocError { layout, .. } => layout,
463+
TryReserveErrorKind::AllocError { layout, .. } => handle_alloc_error(layout),
464464
}
465465
}
466466
}
@@ -535,13 +535,13 @@ where
535535

536536
type Result<T, E: Error> = T
537537
where
538-
E: IntoLayout;
538+
E: HandleAllocError;
539539

540540
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
541541
where
542-
E: IntoLayout,
542+
E: HandleAllocError,
543543
{
544-
result.unwrap_or_else(|e| handle_alloc_error(e.into_layout()))
544+
result.unwrap_or_else(|e| e.handle_alloc_error())
545545
}
546546
}
547547

@@ -624,12 +624,12 @@ where
624624
#[cfg(not(no_global_oom_handling))]
625625
type Result<T, E: Error> = Result<T, E>
626626
where
627-
E: IntoLayout;
627+
E: HandleAllocError;
628628

629629
#[cfg(not(no_global_oom_handling))]
630630
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
631631
where
632-
E: IntoLayout,
632+
E: HandleAllocError,
633633
{
634634
result
635635
}

library/std/src/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,13 @@ unsafe impl Allocator for System {
287287

288288
type Result<T, E: core::error::Error> = T
289289
where
290-
E: IntoLayout;
290+
E: HandleAllocError;
291291

292292
fn map_result<T, E: core::error::Error>(result: Result<T, E>) -> Self::Result<T, E>
293293
where
294-
E: IntoLayout,
294+
E: HandleAllocError,
295295
{
296-
result.unwrap_or_else(|e| handle_alloc_error(e.into_layout()))
296+
result.unwrap_or_else(|e| e.handle_alloc_error())
297297
}
298298
}
299299

0 commit comments

Comments
 (0)