Skip to content

Commit 320b870

Browse files
committed
fix no_global_oom_handling
1 parent b9af8ee commit 320b870

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

library/alloc/src/boxed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,7 @@ impl<I> FromIterator<I> for Box<[I]> {
20142014
}
20152015
}
20162016

2017+
#[cfg(not(no_global_oom_handling))]
20172018
#[stable(feature = "box_slice_clone", since = "1.3.0")]
20182019
impl<T: Clone, A: Allocator<Result<Self, TryReserveError> = Self> + Clone> Clone for Box<[T], A> {
20192020
fn clone(&self) -> Self {

library/alloc/src/falloc.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,25 @@ pub use crate::alloc::{AllocError, Global, GlobalAlloc, Layout, LayoutError};
6060
/// [*currently allocated*]: #currently-allocated-memory
6161
#[unstable(feature = "allocator_api", issue = "32838")]
6262
pub unsafe trait Allocator: crate::alloc::Allocator {
63+
#[cfg(not(no_global_oom_handling))]
6364
#[must_use] // Doesn't actually work
64-
type Result<T, E>
65+
type Result<T, E: Error>
6566
where
66-
E: Error + IntoLayout;
67+
E: IntoLayout;
6768

69+
#[cfg(not(no_global_oom_handling))]
6870
#[must_use]
69-
fn map_result<T, E>(result: Result<T, E>) -> Self::Result<T, E>
71+
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
7072
where
71-
E: Error + IntoLayout;
73+
E: IntoLayout;
74+
75+
#[cfg(no_global_oom_handling)]
76+
#[must_use] // Doesn't actually work
77+
type Result<T, E: Error>;
78+
79+
#[cfg(no_global_oom_handling)]
80+
#[must_use]
81+
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>;
7282
}
7383

7484
#[cfg(not(no_global_oom_handling))]
@@ -84,15 +94,15 @@ pub(crate) fn capacity_overflow() -> ! {
8494
panic!("capacity overflow");
8595
}
8696

97+
#[cfg(not(no_global_oom_handling))]
8798
#[unstable(feature = "allocator_api", issue = "32838")]
8899
pub trait IntoLayout {
89-
#[cfg(not(no_global_oom_handling))]
90100
fn into_layout(self) -> Layout;
91101
}
92102

103+
#[cfg(not(no_global_oom_handling))]
93104
#[unstable(feature = "allocator_api", issue = "32838")]
94105
impl IntoLayout for TryReserveError {
95-
#[cfg(not(no_global_oom_handling))]
96106
fn into_layout(self) -> Layout {
97107
match self.kind() {
98108
TryReserveErrorKind::CapacityOverflow => capacity_overflow(),
@@ -104,14 +114,24 @@ impl IntoLayout for TryReserveError {
104114
#[unstable(feature = "allocator_api", issue = "32838")]
105115
#[cfg(not(no_global_oom_handling))]
106116
unsafe impl<X: crate::alloc::Allocator> Allocator for X {
107-
type Result<T, E> = T
117+
type Result<T, E: Error> = T
108118
where
109-
E: Error + IntoLayout;
119+
E: IntoLayout;
110120

111-
fn map_result<T, E>(result: Result<T, E>) -> Self::Result<T, E>
121+
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E>
112122
where
113-
E: Error + IntoLayout,
123+
E: IntoLayout,
114124
{
115125
result.unwrap_or_else(|error| handle_alloc_error(error.into_layout()))
116126
}
117127
}
128+
129+
#[unstable(feature = "allocator_api", issue = "32838")]
130+
#[cfg(no_global_oom_handling)]
131+
unsafe impl<X: crate::alloc::Allocator> Allocator for X {
132+
type Result<T, E: Error> = Result<T, E>;
133+
134+
fn map_result<T, E: Error>(result: Result<T, E>) -> Self::Result<T, E> {
135+
result
136+
}
137+
}

library/alloc/src/vec/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
5454
#![stable(feature = "rust1", since = "1.0.0")]
5555

56-
#[cfg(not(no_global_oom_handling))]
5756
use core::cmp;
5857
use core::cmp::Ordering;
5958
use core::fmt;
@@ -111,10 +110,8 @@ use self::spec_from_elem::SpecFromElem;
111110

112111
mod spec_from_elem;
113112

114-
#[cfg(not(no_global_oom_handling))]
115113
use self::set_len_on_drop::SetLenOnDrop;
116114

117-
#[cfg(not(no_global_oom_handling))]
118115
mod set_len_on_drop;
119116

120117
#[cfg(not(no_global_oom_handling))]

0 commit comments

Comments
 (0)