Remove the now-unit-struct AllocErr parameter of oom()

This commit is contained in:
Simon Sapin 2018-04-03 16:00:04 +02:00
parent 86753ce1cc
commit 157ff8cd05
12 changed files with 28 additions and 28 deletions

View File

@ -136,8 +136,8 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
align as *mut u8
} else {
let layout = Layout::from_size_align_unchecked(size, align);
Global.alloc(layout).unwrap_or_else(|err| {
Global.oom(err)
Global.alloc(layout).unwrap_or_else(|_| {
Global.oom()
})
}
}
@ -166,7 +166,7 @@ mod tests {
unsafe {
let layout = Layout::from_size_align(1024, 1).unwrap();
let ptr = Global.alloc_zeroed(layout.clone())
.unwrap_or_else(|e| Global.oom(e));
.unwrap_or_else(|_| Global.oom());
let end = ptr.offset(layout.size() as isize);
let mut i = ptr;

View File

@ -555,7 +555,7 @@ impl<T: ?Sized> Arc<T> {
let layout = Layout::for_value(&*fake_ptr);
let mem = Global.alloc(layout)
.unwrap_or_else(|e| Global.oom(e));
.unwrap_or_else(|_| Global.oom());
// Initialize the real ArcInner
let inner = set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>;

View File

@ -52,8 +52,8 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
CoreAlloc::dealloc(self, ptr, layout)
}
fn oom(&mut self, err: AllocErr) -> ! {
CoreAlloc::oom(self, err)
fn oom(&mut self, _: AllocErr) -> ! {
CoreAlloc::oom(self)
}
fn usable_size(&self, layout: &Layout) -> (usize, usize) {

View File

@ -100,7 +100,7 @@ impl<T, A: Alloc> RawVec<T, A> {
};
match result {
Ok(ptr) => ptr,
Err(err) => a.oom(err),
Err(_) => a.oom(),
}
};
@ -316,7 +316,7 @@ impl<T, A: Alloc> RawVec<T, A> {
new_layout);
match ptr_res {
Ok(ptr) => (new_cap, Unique::new_unchecked(ptr as *mut T)),
Err(e) => self.a.oom(e),
Err(_) => self.a.oom(),
}
}
None => {
@ -325,7 +325,7 @@ impl<T, A: Alloc> RawVec<T, A> {
let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 };
match self.a.alloc_array::<T>(new_cap) {
Ok(ptr) => (new_cap, ptr.into()),
Err(e) => self.a.oom(e),
Err(_) => self.a.oom(),
}
}
};
@ -444,7 +444,7 @@ impl<T, A: Alloc> RawVec<T, A> {
pub fn reserve_exact(&mut self, used_cap: usize, needed_extra_cap: usize) {
match self.try_reserve_exact(used_cap, needed_extra_cap) {
Err(CapacityOverflow) => panic!("capacity overflow"),
Err(AllocErr(e)) => self.a.oom(e),
Err(AllocErr(_)) => self.a.oom(),
Ok(()) => { /* yay */ }
}
}
@ -554,7 +554,7 @@ impl<T, A: Alloc> RawVec<T, A> {
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
match self.try_reserve(used_cap, needed_extra_cap) {
Err(CapacityOverflow) => panic!("capacity overflow"),
Err(AllocErr(e)) => self.a.oom(e),
Err(AllocErr(_)) => self.a.oom(),
Ok(()) => { /* yay */ }
}
}
@ -669,7 +669,7 @@ impl<T, A: Alloc> RawVec<T, A> {
old_layout,
new_layout) {
Ok(p) => self.ptr = Unique::new_unchecked(p as *mut T),
Err(err) => self.a.oom(err),
Err(_) => self.a.oom(),
}
}
self.cap = amount;

View File

@ -668,7 +668,7 @@ impl<T: ?Sized> Rc<T> {
let layout = Layout::for_value(&*fake_ptr);
let mem = Global.alloc(layout)
.unwrap_or_else(|e| Global.oom(e));
.unwrap_or_else(|_| Global.oom());
// Initialize the real RcBox
let inner = set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>;

View File

@ -73,8 +73,8 @@ unsafe impl Alloc for System {
Alloc::realloc(&mut &*self, ptr, old_layout, new_layout)
}
fn oom(&mut self, err: AllocErr) -> ! {
Alloc::oom(&mut &*self, err)
fn oom(&mut self) -> ! {
Alloc::oom(&mut &*self)
}
#[inline]
@ -242,7 +242,7 @@ mod platform {
unsafe impl<'a> Alloc for &'a System {
alloc_methods_based_on_global_alloc!();
fn oom(&mut self, err: AllocErr) -> ! {
fn oom(&mut self) -> ! {
use core::fmt::{self, Write};
// Print a message to stderr before aborting to assist with
@ -250,7 +250,7 @@ mod platform {
// memory since we are in an OOM situation. Any errors are ignored
// while printing since there's nothing we can do about them and we
// are about to exit anyways.
drop(writeln!(Stderr, "fatal runtime error: {}", err));
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
unsafe {
::core::intrinsics::abort();
}
@ -459,11 +459,11 @@ mod platform {
}
}
fn oom(&mut self, err: AllocErr) -> ! {
fn oom(&mut self) -> ! {
use core::fmt::{self, Write};
// Same as with unix we ignore all errors here
drop(writeln!(Stderr, "fatal runtime error: {}", err));
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
unsafe {
::core::intrinsics::abort();
}

View File

@ -572,7 +572,7 @@ pub unsafe trait Alloc {
/// instead they should return an appropriate error from the
/// invoked method, and let the client decide whether to invoke
/// this `oom` method in response.
fn oom(&mut self, _: AllocErr) -> ! {
fn oom(&mut self) -> ! {
unsafe { ::intrinsics::abort() }
}

View File

@ -784,7 +784,7 @@ impl<K, V, S> HashMap<K, V, S>
pub fn reserve(&mut self, additional: usize) {
match self.try_reserve(additional) {
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
Ok(()) => { /* yay */ }
}
}

View File

@ -772,7 +772,7 @@ impl<K, V> RawTable<K, V> {
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
match Self::try_new_uninitialized(capacity) {
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
Ok(table) => { table }
}
}
@ -811,7 +811,7 @@ impl<K, V> RawTable<K, V> {
pub fn new(capacity: usize) -> RawTable<K, V> {
match Self::try_new(capacity) {
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
Ok(table) => { table }
}
}

View File

@ -14,8 +14,8 @@ use std::heap::{Heap, Alloc};
fn main() {
unsafe {
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|e| {
Heap.oom(e)
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|_| {
Heap.oom()
});
*ptr.as_ptr() = 4;
assert_eq!(*ptr.as_ptr(), 4);

View File

@ -50,7 +50,7 @@ unsafe fn test_triangle() -> bool {
println!("allocate({:?})", layout);
}
let ret = Heap.alloc(layout.clone()).unwrap_or_else(|e| Heap.oom(e));
let ret = Heap.alloc(layout.clone()).unwrap_or_else(|_| Heap.oom());
if PRINT {
println!("allocate({:?}) = {:?}", layout, ret);
@ -73,7 +73,7 @@ unsafe fn test_triangle() -> bool {
}
let ret = Heap.realloc(ptr, old.clone(), new.clone())
.unwrap_or_else(|e| Heap.oom(e));
.unwrap_or_else(|_| Heap.oom());
if PRINT {
println!("reallocate({:?}, old={:?}, new={:?}) = {:?}",

View File

@ -32,7 +32,7 @@ struct Ccx {
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
unsafe {
let ptr = Heap.alloc(Layout::new::<Bcx>())
.unwrap_or_else(|e| Heap.oom(e));
.unwrap_or_else(|_| Heap.oom());
&*(ptr as *const _)
}
}