Skip to content

Commit 157ff8c

Browse files
committed
Remove the now-unit-struct AllocErr parameter of oom()
1 parent 86753ce commit 157ff8c

File tree

12 files changed

+28
-28
lines changed

12 files changed

+28
-28
lines changed

src/liballoc/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
136136
align as *mut u8
137137
} else {
138138
let layout = Layout::from_size_align_unchecked(size, align);
139-
Global.alloc(layout).unwrap_or_else(|err| {
140-
Global.oom(err)
139+
Global.alloc(layout).unwrap_or_else(|_| {
140+
Global.oom()
141141
})
142142
}
143143
}
@@ -166,7 +166,7 @@ mod tests {
166166
unsafe {
167167
let layout = Layout::from_size_align(1024, 1).unwrap();
168168
let ptr = Global.alloc_zeroed(layout.clone())
169-
.unwrap_or_else(|e| Global.oom(e));
169+
.unwrap_or_else(|_| Global.oom());
170170

171171
let end = ptr.offset(layout.size() as isize);
172172
let mut i = ptr;

src/liballoc/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<T: ?Sized> Arc<T> {
555555
let layout = Layout::for_value(&*fake_ptr);
556556

557557
let mem = Global.alloc(layout)
558-
.unwrap_or_else(|e| Global.oom(e));
558+
.unwrap_or_else(|_| Global.oom());
559559

560560
// Initialize the real ArcInner
561561
let inner = set_data_ptr(ptr as *mut T, mem) as *mut ArcInner<T>;

src/liballoc/heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
5252
CoreAlloc::dealloc(self, ptr, layout)
5353
}
5454

55-
fn oom(&mut self, err: AllocErr) -> ! {
56-
CoreAlloc::oom(self, err)
55+
fn oom(&mut self, _: AllocErr) -> ! {
56+
CoreAlloc::oom(self)
5757
}
5858

5959
fn usable_size(&self, layout: &Layout) -> (usize, usize) {

src/liballoc/raw_vec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<T, A: Alloc> RawVec<T, A> {
100100
};
101101
match result {
102102
Ok(ptr) => ptr,
103-
Err(err) => a.oom(err),
103+
Err(_) => a.oom(),
104104
}
105105
};
106106

@@ -316,7 +316,7 @@ impl<T, A: Alloc> RawVec<T, A> {
316316
new_layout);
317317
match ptr_res {
318318
Ok(ptr) => (new_cap, Unique::new_unchecked(ptr as *mut T)),
319-
Err(e) => self.a.oom(e),
319+
Err(_) => self.a.oom(),
320320
}
321321
}
322322
None => {
@@ -325,7 +325,7 @@ impl<T, A: Alloc> RawVec<T, A> {
325325
let new_cap = if elem_size > (!0) / 8 { 1 } else { 4 };
326326
match self.a.alloc_array::<T>(new_cap) {
327327
Ok(ptr) => (new_cap, ptr.into()),
328-
Err(e) => self.a.oom(e),
328+
Err(_) => self.a.oom(),
329329
}
330330
}
331331
};
@@ -444,7 +444,7 @@ impl<T, A: Alloc> RawVec<T, A> {
444444
pub fn reserve_exact(&mut self, used_cap: usize, needed_extra_cap: usize) {
445445
match self.try_reserve_exact(used_cap, needed_extra_cap) {
446446
Err(CapacityOverflow) => panic!("capacity overflow"),
447-
Err(AllocErr(e)) => self.a.oom(e),
447+
Err(AllocErr(_)) => self.a.oom(),
448448
Ok(()) => { /* yay */ }
449449
}
450450
}
@@ -554,7 +554,7 @@ impl<T, A: Alloc> RawVec<T, A> {
554554
pub fn reserve(&mut self, used_cap: usize, needed_extra_cap: usize) {
555555
match self.try_reserve(used_cap, needed_extra_cap) {
556556
Err(CapacityOverflow) => panic!("capacity overflow"),
557-
Err(AllocErr(e)) => self.a.oom(e),
557+
Err(AllocErr(_)) => self.a.oom(),
558558
Ok(()) => { /* yay */ }
559559
}
560560
}
@@ -669,7 +669,7 @@ impl<T, A: Alloc> RawVec<T, A> {
669669
old_layout,
670670
new_layout) {
671671
Ok(p) => self.ptr = Unique::new_unchecked(p as *mut T),
672-
Err(err) => self.a.oom(err),
672+
Err(_) => self.a.oom(),
673673
}
674674
}
675675
self.cap = amount;

src/liballoc/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<T: ?Sized> Rc<T> {
668668
let layout = Layout::for_value(&*fake_ptr);
669669

670670
let mem = Global.alloc(layout)
671-
.unwrap_or_else(|e| Global.oom(e));
671+
.unwrap_or_else(|_| Global.oom());
672672

673673
// Initialize the real RcBox
674674
let inner = set_data_ptr(ptr as *mut T, mem) as *mut RcBox<T>;

src/liballoc_system/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ unsafe impl Alloc for System {
7373
Alloc::realloc(&mut &*self, ptr, old_layout, new_layout)
7474
}
7575

76-
fn oom(&mut self, err: AllocErr) -> ! {
77-
Alloc::oom(&mut &*self, err)
76+
fn oom(&mut self) -> ! {
77+
Alloc::oom(&mut &*self)
7878
}
7979

8080
#[inline]
@@ -242,15 +242,15 @@ mod platform {
242242
unsafe impl<'a> Alloc for &'a System {
243243
alloc_methods_based_on_global_alloc!();
244244

245-
fn oom(&mut self, err: AllocErr) -> ! {
245+
fn oom(&mut self) -> ! {
246246
use core::fmt::{self, Write};
247247

248248
// Print a message to stderr before aborting to assist with
249249
// debugging. It is critical that this code does not allocate any
250250
// memory since we are in an OOM situation. Any errors are ignored
251251
// while printing since there's nothing we can do about them and we
252252
// are about to exit anyways.
253-
drop(writeln!(Stderr, "fatal runtime error: {}", err));
253+
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
254254
unsafe {
255255
::core::intrinsics::abort();
256256
}
@@ -459,11 +459,11 @@ mod platform {
459459
}
460460
}
461461

462-
fn oom(&mut self, err: AllocErr) -> ! {
462+
fn oom(&mut self) -> ! {
463463
use core::fmt::{self, Write};
464464

465465
// Same as with unix we ignore all errors here
466-
drop(writeln!(Stderr, "fatal runtime error: {}", err));
466+
drop(writeln!(Stderr, "fatal runtime error: {}", AllocErr));
467467
unsafe {
468468
::core::intrinsics::abort();
469469
}

src/libcore/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ pub unsafe trait Alloc {
572572
/// instead they should return an appropriate error from the
573573
/// invoked method, and let the client decide whether to invoke
574574
/// this `oom` method in response.
575-
fn oom(&mut self, _: AllocErr) -> ! {
575+
fn oom(&mut self) -> ! {
576576
unsafe { ::intrinsics::abort() }
577577
}
578578

src/libstd/collections/hash/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<K, V, S> HashMap<K, V, S>
784784
pub fn reserve(&mut self, additional: usize) {
785785
match self.try_reserve(additional) {
786786
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
787-
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
787+
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
788788
Ok(()) => { /* yay */ }
789789
}
790790
}

src/libstd/collections/hash/table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<K, V> RawTable<K, V> {
772772
unsafe fn new_uninitialized(capacity: usize) -> RawTable<K, V> {
773773
match Self::try_new_uninitialized(capacity) {
774774
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
775-
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
775+
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
776776
Ok(table) => { table }
777777
}
778778
}
@@ -811,7 +811,7 @@ impl<K, V> RawTable<K, V> {
811811
pub fn new(capacity: usize) -> RawTable<K, V> {
812812
match Self::try_new(capacity) {
813813
Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"),
814-
Err(CollectionAllocErr::AllocErr(e)) => Global.oom(e),
814+
Err(CollectionAllocErr::AllocErr(_)) => Global.oom(),
815815
Ok(table) => { table }
816816
}
817817
}

src/test/run-pass/allocator-alloc-one.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::heap::{Heap, Alloc};
1414

1515
fn main() {
1616
unsafe {
17-
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|e| {
18-
Heap.oom(e)
17+
let ptr = Heap.alloc_one::<i32>().unwrap_or_else(|_| {
18+
Heap.oom()
1919
});
2020
*ptr.as_ptr() = 4;
2121
assert_eq!(*ptr.as_ptr(), 4);

0 commit comments

Comments
 (0)