Skip to content

Commit 6689a37

Browse files
committed
move to core to fix tests
1 parent 0e723c3 commit 6689a37

File tree

16 files changed

+300
-672
lines changed

16 files changed

+300
-672
lines changed

library/alloc/src/alloc.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ use core::ptr::Unique;
1010
#[cfg(not(test))]
1111
use core::ptr::{self, NonNull};
1212

13-
#[unstable(feature = "allocator_api", issue = "32838")]
14-
pub use crate::falloc::{Allocator, Fallible};
15-
#[unstable(feature = "allocator_api", issue = "32838")]
16-
#[cfg(not(no_global_oom_handling))]
17-
pub use crate::falloc::{FallibleAdapter, Fatal, HandleAllocError, InfallibleAdapter};
1813
#[stable(feature = "alloc_module", since = "1.28.0")]
1914
#[doc(inline)]
20-
#[allow(deprecated)]
21-
pub use core::alloc::{AllocError, GlobalAlloc, Layout, LayoutErr, LayoutError};
15+
pub use core::alloc::*;
2216

2317
#[cfg(test)]
2418
mod tests;
@@ -454,3 +448,28 @@ impl<T: Copy> WriteCloneIntoRaw for T {
454448
unsafe { target.copy_from_nonoverlapping(self, 1) };
455449
}
456450
}
451+
452+
#[cfg(not(no_global_oom_handling))]
453+
use crate::collections::{TryReserveError, TryReserveErrorKind};
454+
455+
// One central function responsible for reporting capacity overflows. This'll
456+
// ensure that the code generation related to these panics is minimal as there's
457+
// only one location which panics rather than a bunch throughout the module.
458+
#[cfg(not(no_global_oom_handling))]
459+
pub(crate) fn capacity_overflow() -> ! {
460+
panic!("capacity overflow");
461+
}
462+
463+
#[cfg(not(no_global_oom_handling))]
464+
#[unstable(feature = "allocator_api", issue = "32838")]
465+
impl HandleAllocError for TryReserveError {
466+
fn handle_alloc_error(self) -> ! {
467+
match self.kind() {
468+
TryReserveErrorKind::CapacityOverflow => capacity_overflow(),
469+
TryReserveErrorKind::AllocError { layout, .. } => handle_alloc_error(layout),
470+
}
471+
}
472+
}
473+
474+
pub(crate) type AllocResult<A, T, E> =
475+
<<A as Allocator>::ErrorHandling as ErrorHandling>::Result<T, E>;

library/alloc/src/boxed.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ use core::pin::Pin;
165165
use core::ptr::{self, Unique};
166166
use core::task::{Context, Poll};
167167

168+
#[cfg(not(no_global_oom_handling))]
169+
use crate::alloc::Fatal;
168170
#[cfg(not(no_global_oom_handling))]
169171
use crate::alloc::{handle_alloc_error, WriteCloneIntoRaw};
172+
use crate::alloc::{AllocError, AllocResult, Allocator, ErrorHandling, Global, Layout};
170173
#[cfg(not(no_global_oom_handling))]
171174
use crate::borrow::Cow;
172175
use crate::collections::TryReserveError;
173-
#[cfg(not(no_global_oom_handling))]
174-
use crate::falloc::Fatal;
175-
use crate::falloc::{AllocError, AllocResult, Allocator, ErrorHandling, Global, Layout};
176176
use crate::raw_vec::RawVec;
177177
#[cfg(not(no_global_oom_handling))]
178178
use crate::str::from_boxed_utf8_unchecked;

library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use core::slice;
2222
#[allow(unused_imports)]
2323
use core::mem;
2424

25+
use crate::alloc::{AllocResult, Allocator, ErrorHandling, Fatal, Global};
2526
use crate::collections::TryReserveError;
2627
use crate::collections::TryReserveErrorKind;
27-
use crate::falloc::{AllocResult, Allocator, ErrorHandling, Fatal, Global};
2828
use crate::raw_vec::RawVec;
2929
use crate::vec::Vec;
3030

library/alloc/src/falloc.rs

Lines changed: 0 additions & 638 deletions
This file was deleted.

library/alloc/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ mod raw_vec;
226226

227227
pub mod alloc;
228228

229-
// Fallible allocation experiment
230-
231-
mod falloc;
232-
233229
// Primitive types using the heaps above
234230

235231
// Need to conditionally define the mod from `boxed.rs` to avoid

library/alloc/src/raw_vec/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cell::Cell;
33

44
#[test]
55
fn allocator_param() -> Result<(), TryReserveError> {
6-
use crate::alloc::AllocError;
6+
use crate::alloc::{AllocError, Fatal};
77

88
// Writing a test of integration between third-party
99
// allocators and `RawVec` is a little tricky because the `RawVec`
@@ -37,6 +37,7 @@ fn allocator_param() -> Result<(), TryReserveError> {
3737
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
3838
unsafe { Global.deallocate(ptr, layout) }
3939
}
40+
type ErrorHandling = Fatal;
4041
}
4142

4243
let a = BoundedAlloc { fuel: Cell::new(500) };

library/alloc/src/slice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ use crate::alloc::Allocator;
2626
#[cfg(not(no_global_oom_handling))]
2727
use crate::alloc::{self, Global};
2828
#[cfg(not(no_global_oom_handling))]
29+
use crate::alloc::{AllocResult, ErrorHandling};
30+
#[cfg(not(no_global_oom_handling))]
2931
use crate::borrow::ToOwned;
3032
use crate::boxed::Box;
3133
#[cfg(not(no_global_oom_handling))]
3234
use crate::collections::TryReserveError;
33-
#[cfg(not(no_global_oom_handling))]
34-
use crate::falloc::{AllocResult, ErrorHandling};
3535
use crate::vec::Vec;
3636

3737
#[cfg(test)]
@@ -837,7 +837,7 @@ impl<T: Clone> ToOwned for [T] {
837837

838838
#[cfg(test)]
839839
fn to_owned(&self) -> Vec<T> {
840-
hack::to_vec(self, Global)
840+
<Global as Allocator>::ErrorHandling::map_result(hack::to_vec(self, Global))
841841
}
842842

843843
fn clone_into(&self, target: &mut Vec<T>) {

library/alloc/src/vec/into_iter.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#[cfg(not(no_global_oom_handling))]
22
use super::AsVecIntoIter;
3+
#[cfg(test)]
4+
use crate::alloc::ErrorHandling;
5+
#[cfg(not(no_global_oom_handling))]
6+
use crate::alloc::Fatal;
37
use crate::alloc::{Allocator, Global};
48
#[cfg(not(no_global_oom_handling))]
59
use crate::collections::VecDeque;
6-
#[cfg(not(no_global_oom_handling))]
7-
use crate::falloc::Fatal;
810
use crate::raw_vec::RawVec;
911
use core::array;
1012
use core::fmt;
@@ -395,7 +397,11 @@ where
395397
}
396398
#[cfg(test)]
397399
fn clone(&self) -> Self {
398-
crate::slice::to_vec(self.as_slice(), self.alloc.deref().clone()).into_iter()
400+
A::ErrorHandling::map_result(crate::slice::to_vec(
401+
self.as_slice(),
402+
self.alloc.deref().clone(),
403+
))
404+
.into_iter()
399405
}
400406
}
401407

library/alloc/src/vec/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ use core::ops::{self, Index, IndexMut, Range, RangeBounds};
6464
use core::ptr::{self, NonNull};
6565
use core::slice::{self, SliceIndex};
6666

67+
#[cfg(not(no_global_oom_handling))]
68+
use crate::alloc::Fatal;
69+
use crate::alloc::{AllocResult, Allocator, ErrorHandling, Global};
6770
use crate::borrow::{Cow, ToOwned};
6871
use crate::boxed::Box;
6972
use crate::collections::{TryReserveError, TryReserveErrorKind};
70-
#[cfg(not(no_global_oom_handling))]
71-
use crate::falloc::Fatal;
72-
use crate::falloc::{AllocResult, Allocator, ErrorHandling, Global};
7373
use crate::raw_vec::RawVec;
7474

7575
#[unstable(feature = "drain_filter", reason = "recently added", issue = "43244")]
@@ -2683,7 +2683,7 @@ where
26832683
#[cfg(test)]
26842684
fn clone(&self) -> Self {
26852685
let alloc = self.allocator().clone();
2686-
crate::slice::to_vec(&**self, alloc)
2686+
<Global as Allocator>::ErrorHandling::map_result(crate::slice::to_vec(&**self, alloc))
26872687
}
26882688

26892689
fn clone_from(&mut self, other: &Self) {
@@ -3127,7 +3127,7 @@ impl<T: Clone> From<&[T]> for Vec<T> {
31273127
}
31283128
#[cfg(test)]
31293129
fn from(s: &[T]) -> Vec<T> {
3130-
crate::slice::to_vec(s, Global)
3130+
<Global as Allocator>::ErrorHandling::map_result(crate::slice::to_vec(s, Global))
31313131
}
31323132
}
31333133

@@ -3147,7 +3147,7 @@ impl<T: Clone> From<&mut [T]> for Vec<T> {
31473147
}
31483148
#[cfg(test)]
31493149
fn from(s: &mut [T]) -> Vec<T> {
3150-
crate::slice::to_vec(s, Global)
3150+
<Global as Allocator>::ErrorHandling::map_result(crate::slice::to_vec(s, Global))
31513151
}
31523152
}
31533153

library/alloc/src/vec/spec_from_elem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::ptr;
22

3+
use crate::alloc::Allocator;
34
use crate::collections::TryReserveError;
4-
use crate::falloc::Allocator;
55

66
use super::{IsZero, Vec};
77

library/alloc/src/vec/spec_from_iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::mem::ManuallyDrop;
22
use core::ptr;
33

4-
use crate::falloc::{Allocator, ErrorHandling, Global};
4+
use crate::alloc::{Allocator, ErrorHandling, Global};
55

66
use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec};
77

library/alloc/src/vec/spec_from_iter_nested.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::cmp;
22
use core::iter::TrustedLen;
33
use core::ptr;
44

5-
use crate::falloc::{Allocator, ErrorHandling, Global};
5+
use crate::alloc::{Allocator, ErrorHandling, Global};
66
use crate::raw_vec::RawVec;
77

88
use super::{SpecExtend, Vec};

library/alloc/src/vec/splice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::falloc::{Allocator, ErrorHandling, Fatal, Global};
1+
use crate::alloc::{Allocator, ErrorHandling, Fatal, Global};
22
use core::ptr;
33
use core::slice;
44

library/alloc/tests/boxed.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::alloc::{AllocError, Allocator, Layout};
1+
use core::alloc::{AllocError, Allocator, Layout, Fatal};
22
use core::cell::Cell;
33
use core::mem::MaybeUninit;
44
use core::ptr::NonNull;
@@ -178,4 +178,6 @@ unsafe impl Allocator for ConstAllocator {
178178
{
179179
self
180180
}
181+
182+
type ErrorHandling = Fatal;
181183
}

0 commit comments

Comments
 (0)