Skip to content
This repository was archived by the owner on Nov 27, 2020. It is now read-only.

Commit 8aec886

Browse files
committed
Switch defaults to PanicHandler<Global>
1 parent b1addb0 commit 8aec886

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

src/alloc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use liballoc::alloc::{handle_alloc_error, Layout};
1414
use std::alloc::System;
1515

1616
mod panic_adaptor;
17+
pub use self::panic_adaptor::PanicAdapter;
1718

1819
/// Allocate memory with the global allocator.
1920
///

src/boxed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
//! [`NonZeroLayout::for_value(&*value)`]: crate::alloc::NonZeroLayout::for_value
8080
8181
use crate::{
82-
alloc::{AllocRef, BuildAllocRef, DeallocRef, Global, NonZeroLayout},
82+
alloc::{AllocRef, BuildAllocRef, DeallocRef, Global, NonZeroLayout, PanicAdapter},
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 = PanicAdapter<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, PanicAdapter(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(PanicAdapter(Global))
160160
}
161161

162162
/// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
@@ -309,7 +309,7 @@ impl<T> Box<[T]> {
309309
#[inline(always)]
310310
#[must_use]
311311
pub fn new_uninit_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
312-
Self::new_uninit_slice_in(len, Global)
312+
Self::new_uninit_slice_in(len, PanicAdapter(Global))
313313
}
314314
}
315315

@@ -503,7 +503,7 @@ impl<T: ?Sized> Box<T> {
503503
#[allow(clippy::inline_always)]
504504
#[inline(always)]
505505
pub unsafe fn from_raw(raw: *mut T) -> Self {
506-
Self::from_raw_in(raw, Global)
506+
Self::from_raw_in(raw, PanicAdapter(Global))
507507
}
508508
}
509509

src/raw_vec.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::{
77
DeallocRef,
88
Global,
99
NonZeroLayout,
10+
PanicAdapter,
1011
ReallocRef,
1112
},
1213
boxed::Box,
@@ -51,7 +52,7 @@ use core::{
5152
/// field. This allows zero-sized types to not be special-cased by consumers of
5253
/// this type.
5354
// Using `NonNull` + `PhantomData` instead of `Unique` to stay on stable as long as possible
54-
pub struct RawVec<T, A: DeallocRef = Global> {
55+
pub struct RawVec<T, A: DeallocRef = PanicAdapter<Global>> {
5556
ptr: Unique<T>,
5657
capacity: usize,
5758
build_alloc: A::BuildAlloc,
@@ -89,7 +90,7 @@ impl<T> RawVec<T> {
8990
ptr: Unique::empty(),
9091
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
9192
capacity: [0, !0][(mem::size_of::<T>() == 0) as usize],
92-
build_alloc: Global,
93+
build_alloc: PanicAdapter(Global),
9394
}
9495
}
9596

@@ -110,7 +111,7 @@ impl<T> RawVec<T> {
110111
#[inline]
111112
#[must_use]
112113
pub fn with_capacity(capacity: usize) -> Self {
113-
Self::with_capacity_in(capacity, Global)
114+
Self::with_capacity_in(capacity, PanicAdapter(Global))
114115
}
115116

116117
/// Like `with_capacity`, but guarantees the buffer is zeroed.
@@ -126,7 +127,7 @@ impl<T> RawVec<T> {
126127
#[inline]
127128
#[must_use]
128129
pub fn with_capacity_zeroed(capacity: usize) -> Self {
129-
Self::with_capacity_zeroed_in(capacity, Global)
130+
Self::with_capacity_zeroed_in(capacity, PanicAdapter(Global))
130131
}
131132

132133
/// Reconstitutes a `RawVec` from a pointer, and capacity.
@@ -138,7 +139,7 @@ impl<T> RawVec<T> {
138139
/// If the ptr and capacity come from a `RawVec` created with `Global`, then this is guaranteed.
139140
#[inline]
140141
pub unsafe fn from_raw_parts(ptr: *mut T, capacity: usize) -> Self {
141-
Self::from_raw_parts_in(ptr, capacity, Global)
142+
Self::from_raw_parts_in(ptr, capacity, PanicAdapter(Global))
142143
}
143144
}
144145

src/string.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//! ```
5353
5454
use crate::{
55-
alloc::{AllocRef, DeallocRef, Global, ReallocRef},
55+
alloc::{AllocRef, DeallocRef, Global, PanicAdapter, ReallocRef},
5656
boxed::Box,
5757
collections::CollectionAllocErr,
5858
iter::TryExtend,
@@ -312,7 +312,7 @@ pub use liballoc::string::{ParseError, ToString};
312312
/// [`Deref`]: ../../std/ops/trait.Deref.html
313313
/// [`as_str()`]: struct.String.html#method.as_str
314314
#[derive(PartialOrd, Eq, Ord)]
315-
pub struct String<A: DeallocRef = Global> {
315+
pub struct String<A: DeallocRef = PanicAdapter<Global>> {
316316
vec: Vec<u8, A>,
317317
}
318318

@@ -354,7 +354,7 @@ pub struct String<A: DeallocRef = Global> {
354354
/// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
355355
/// ```
356356
#[derive(Debug)]
357-
pub struct FromUtf8Error<A: DeallocRef = Global> {
357+
pub struct FromUtf8Error<A: DeallocRef = PanicAdapter<Global>> {
358358
bytes: Vec<u8, A>,
359359
error: Utf8Error,
360360
}
@@ -451,7 +451,7 @@ impl String {
451451
#[inline]
452452
#[must_use]
453453
pub fn with_capacity(capacity: usize) -> Self {
454-
Self::with_capacity_in(capacity, Global)
454+
Self::with_capacity_in(capacity, PanicAdapter(Global))
455455
}
456456

457457
/// Decode a UTF-16 encoded vector `v` into a `String`, returning [`Err`]
@@ -475,7 +475,7 @@ impl String {
475475
/// assert!(String::from_utf16(v).is_err());
476476
/// ```
477477
pub fn from_utf16(v: &[u16]) -> Result<Self, FromUtf16Error> {
478-
Self::from_utf16_in(v, Global)
478+
Self::from_utf16_in(v, PanicAdapter(Global))
479479
}
480480

481481
/// Decode a UTF-16 encoded slice `v` into a `String`, replacing
@@ -560,7 +560,7 @@ impl String {
560560
/// ```
561561
#[inline]
562562
pub unsafe fn from_raw_parts(buf: *mut u8, length: usize, capacity: usize) -> Self {
563-
Self::from_raw_parts_in(buf, length, capacity, Global)
563+
Self::from_raw_parts_in(buf, length, capacity, PanicAdapter(Global))
564564
}
565565
}
566566

src/vec.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@
6969
//! [`vec!`]: ../macro.vec.html
7070
7171
use crate::{
72-
alloc::{handle_alloc_error, AllocRef, BuildAllocRef, DeallocRef, Global, ReallocRef},
72+
alloc::{
73+
handle_alloc_error,
74+
AllocRef,
75+
BuildAllocRef,
76+
DeallocRef,
77+
Global,
78+
PanicAdapter,
79+
ReallocRef,
80+
},
7381
boxed::Box,
7482
clone::CloneIn,
7583
collections::CollectionAllocErr,
@@ -328,7 +336,7 @@ use core::{
328336
/// [`insert`]: Self::insert()
329337
/// [`reserve`]: Self::reserve
330338
/// [owned slice]: crate::boxed::Box
331-
pub struct Vec<T, A: DeallocRef = Global> {
339+
pub struct Vec<T, A: DeallocRef = PanicAdapter<Global>> {
332340
buf: RawVec<T, A>,
333341
len: usize,
334342
}
@@ -401,7 +409,7 @@ impl<T> Vec<T> {
401409
#[inline]
402410
#[must_use]
403411
pub fn with_capacity(capacity: usize) -> Self {
404-
Self::with_capacity_in(capacity, Global)
412+
Self::with_capacity_in(capacity, PanicAdapter(Global))
405413
}
406414

407415
/// Creates a `Vec<T>` directly from the raw components of another vector.
@@ -664,7 +672,7 @@ impl<T, A: DeallocRef> Vec<T, A> {
664672
/// # Examples
665673
///
666674
/// ```
667-
/// use alloc_wg::{alloc::Global, collections::CollectionAllocErr, vec::Vec};
675+
/// use alloc_wg::{alloc::PanicAdapter<Global>, collections::CollectionAllocErr, vec::Vec};
668676
///
669677
/// fn process_data(data: &[u32]) -> Result<Vec<u32>, CollectionAllocErr<Global>> {
670678
/// let mut output = Vec::new();
@@ -2024,7 +2032,7 @@ impl<T: PartialEq, A: DeallocRef> Vec<T, A> {
20242032

20252033
#[doc(hidden)]
20262034
pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
2027-
from_elem_in(elem, n, Global)
2035+
from_elem_in(elem, n, PanicAdapter(Global))
20282036
}
20292037

20302038
#[doc(hidden)]
@@ -2267,7 +2275,10 @@ impl<T> FromIterator<T> for Vec<T> {
22672275
#[inline]
22682276
#[must_use]
22692277
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
2270-
<Self as SpecExtend<T, I::IntoIter, Global>>::from_iter_in(iter.into_iter(), Global)
2278+
<Self as SpecExtend<T, I::IntoIter, PanicAdapter<Global>>>::from_iter_in(
2279+
iter.into_iter(),
2280+
PanicAdapter(Global),
2281+
)
22712282
}
22722283
}
22732284

@@ -2896,7 +2907,7 @@ impl From<&str> for Vec<u8> {
28962907
///
28972908
/// [`Vec`]: struct.Vec.html
28982909
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
2899-
pub struct IntoIter<T, A: DeallocRef = Global> {
2910+
pub struct IntoIter<T, A: DeallocRef = PanicAdapter<Global>> {
29002911
buf: RawVec<T, A>,
29012912
ptr: *const T,
29022913
end: *const T,
@@ -3042,7 +3053,7 @@ impl<T, A: DeallocRef> Drop for IntoIter<T, A> {
30423053
///
30433054
/// [`drain`]: struct.Vec.html#method.drain
30443055
/// [`Vec`]: struct.Vec.html
3045-
pub struct Drain<'a, T, A: DeallocRef = Global> {
3056+
pub struct Drain<'a, T, A: DeallocRef = PanicAdapter<Global>> {
30463057
/// Index of tail to preserve
30473058
tail_start: usize,
30483059
/// Length of tail
@@ -3135,7 +3146,7 @@ impl<T, A: DeallocRef> FusedIterator for Drain<'_, T, A> {}
31353146
/// [`splice()`]: struct.Vec.html#method.splice
31363147
/// [`Vec`]: struct.Vec.html
31373148
#[derive(Debug)]
3138-
pub struct Splice<'a, I: Iterator + 'a, A = Global>
3149+
pub struct Splice<'a, I: Iterator + 'a, A = PanicAdapter<Global>>
31393150
where
31403151
A: ReallocRef,
31413152
{
@@ -3257,7 +3268,7 @@ where
32573268

32583269
/// An iterator produced by calling `drain_filter` on Vec.
32593270
// #[derive(Debug)]
3260-
pub struct DrainFilter<'a, T, F, A: DeallocRef = Global>
3271+
pub struct DrainFilter<'a, T, F, A: DeallocRef = PanicAdapter<Global>>
32613272
where
32623273
F: FnMut(&mut T) -> bool,
32633274
{
@@ -3320,7 +3331,7 @@ where
33203331
F: FnMut(&mut T) -> bool,
33213332
{
33223333
fn drop(&mut self) {
3323-
struct BackshiftOnDrop<'a, 'b, T, F, A: DeallocRef = Global>
3334+
struct BackshiftOnDrop<'a, 'b, T, F, A: DeallocRef = PanicAdapter<Global>>
33243335
where
33253336
F: FnMut(&mut T) -> bool,
33263337
{

0 commit comments

Comments
 (0)