Skip to content

Commit 93a9ad4

Browse files
committed
Remove the now-unit-struct AllocErr field inside CollectionAllocErr
1 parent 157ff8c commit 93a9ad4

File tree

7 files changed

+29
-29
lines changed

7 files changed

+29
-29
lines changed

src/liballoc/raw_vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(_)) => self.a.oom(),
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(_)) => self.a.oom(),
557+
Err(AllocErr) => self.a.oom(),
558558
Ok(()) => { /* yay */ }
559559
}
560560
}

src/liballoc/tests/string.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,11 @@ fn test_try_reserve() {
575575
} else { panic!("usize::MAX should trigger an overflow!") }
576576
} else {
577577
// Check isize::MAX + 1 is an OOM
578-
if let Err(AllocErr(_)) = empty_string.try_reserve(MAX_CAP + 1) {
578+
if let Err(AllocErr) = empty_string.try_reserve(MAX_CAP + 1) {
579579
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
580580

581581
// Check usize::MAX is an OOM
582-
if let Err(AllocErr(_)) = empty_string.try_reserve(MAX_USIZE) {
582+
if let Err(AllocErr) = empty_string.try_reserve(MAX_USIZE) {
583583
} else { panic!("usize::MAX should trigger an OOM!") }
584584
}
585585
}
@@ -599,7 +599,7 @@ fn test_try_reserve() {
599599
if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 9) {
600600
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
601601
} else {
602-
if let Err(AllocErr(_)) = ten_bytes.try_reserve(MAX_CAP - 9) {
602+
if let Err(AllocErr) = ten_bytes.try_reserve(MAX_CAP - 9) {
603603
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
604604
}
605605
// Should always overflow in the add-to-len
@@ -637,10 +637,10 @@ fn test_try_reserve_exact() {
637637
if let Err(CapacityOverflow) = empty_string.try_reserve_exact(MAX_USIZE) {
638638
} else { panic!("usize::MAX should trigger an overflow!") }
639639
} else {
640-
if let Err(AllocErr(_)) = empty_string.try_reserve_exact(MAX_CAP + 1) {
640+
if let Err(AllocErr) = empty_string.try_reserve_exact(MAX_CAP + 1) {
641641
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
642642

643-
if let Err(AllocErr(_)) = empty_string.try_reserve_exact(MAX_USIZE) {
643+
if let Err(AllocErr) = empty_string.try_reserve_exact(MAX_USIZE) {
644644
} else { panic!("usize::MAX should trigger an OOM!") }
645645
}
646646
}
@@ -659,7 +659,7 @@ fn test_try_reserve_exact() {
659659
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
660660
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
661661
} else {
662-
if let Err(AllocErr(_)) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
662+
if let Err(AllocErr) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
663663
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
664664
}
665665
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_USIZE) {

src/liballoc/tests/vec.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,11 +1016,11 @@ fn test_try_reserve() {
10161016
} else { panic!("usize::MAX should trigger an overflow!") }
10171017
} else {
10181018
// Check isize::MAX + 1 is an OOM
1019-
if let Err(AllocErr(_)) = empty_bytes.try_reserve(MAX_CAP + 1) {
1019+
if let Err(AllocErr) = empty_bytes.try_reserve(MAX_CAP + 1) {
10201020
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
10211021

10221022
// Check usize::MAX is an OOM
1023-
if let Err(AllocErr(_)) = empty_bytes.try_reserve(MAX_USIZE) {
1023+
if let Err(AllocErr) = empty_bytes.try_reserve(MAX_USIZE) {
10241024
} else { panic!("usize::MAX should trigger an OOM!") }
10251025
}
10261026
}
@@ -1040,7 +1040,7 @@ fn test_try_reserve() {
10401040
if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 9) {
10411041
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
10421042
} else {
1043-
if let Err(AllocErr(_)) = ten_bytes.try_reserve(MAX_CAP - 9) {
1043+
if let Err(AllocErr) = ten_bytes.try_reserve(MAX_CAP - 9) {
10441044
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
10451045
}
10461046
// Should always overflow in the add-to-len
@@ -1063,7 +1063,7 @@ fn test_try_reserve() {
10631063
if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 9) {
10641064
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
10651065
} else {
1066-
if let Err(AllocErr(_)) = ten_u32s.try_reserve(MAX_CAP/4 - 9) {
1066+
if let Err(AllocErr) = ten_u32s.try_reserve(MAX_CAP/4 - 9) {
10671067
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
10681068
}
10691069
// Should fail in the mul-by-size
@@ -1103,10 +1103,10 @@ fn test_try_reserve_exact() {
11031103
if let Err(CapacityOverflow) = empty_bytes.try_reserve_exact(MAX_USIZE) {
11041104
} else { panic!("usize::MAX should trigger an overflow!") }
11051105
} else {
1106-
if let Err(AllocErr(_)) = empty_bytes.try_reserve_exact(MAX_CAP + 1) {
1106+
if let Err(AllocErr) = empty_bytes.try_reserve_exact(MAX_CAP + 1) {
11071107
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
11081108

1109-
if let Err(AllocErr(_)) = empty_bytes.try_reserve_exact(MAX_USIZE) {
1109+
if let Err(AllocErr) = empty_bytes.try_reserve_exact(MAX_USIZE) {
11101110
} else { panic!("usize::MAX should trigger an OOM!") }
11111111
}
11121112
}
@@ -1125,7 +1125,7 @@ fn test_try_reserve_exact() {
11251125
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
11261126
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
11271127
} else {
1128-
if let Err(AllocErr(_)) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
1128+
if let Err(AllocErr) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
11291129
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
11301130
}
11311131
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_USIZE) {
@@ -1146,7 +1146,7 @@ fn test_try_reserve_exact() {
11461146
if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) {
11471147
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
11481148
} else {
1149-
if let Err(AllocErr(_)) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) {
1149+
if let Err(AllocErr) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) {
11501150
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
11511151
}
11521152
if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_USIZE - 20) {

src/liballoc/tests/vec_deque.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ fn test_try_reserve() {
10731073
// VecDeque starts with capacity 7, always adds 1 to the capacity
10741074
// and also rounds the number to next power of 2 so this is the
10751075
// furthest we can go without triggering CapacityOverflow
1076-
if let Err(AllocErr(_)) = empty_bytes.try_reserve(MAX_CAP) {
1076+
if let Err(AllocErr) = empty_bytes.try_reserve(MAX_CAP) {
10771077
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
10781078
}
10791079
}
@@ -1093,7 +1093,7 @@ fn test_try_reserve() {
10931093
if let Err(CapacityOverflow) = ten_bytes.try_reserve(MAX_CAP - 9) {
10941094
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
10951095
} else {
1096-
if let Err(AllocErr(_)) = ten_bytes.try_reserve(MAX_CAP - 9) {
1096+
if let Err(AllocErr) = ten_bytes.try_reserve(MAX_CAP - 9) {
10971097
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
10981098
}
10991099
// Should always overflow in the add-to-len
@@ -1116,7 +1116,7 @@ fn test_try_reserve() {
11161116
if let Err(CapacityOverflow) = ten_u32s.try_reserve(MAX_CAP/4 - 9) {
11171117
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
11181118
} else {
1119-
if let Err(AllocErr(_)) = ten_u32s.try_reserve(MAX_CAP/4 - 9) {
1119+
if let Err(AllocErr) = ten_u32s.try_reserve(MAX_CAP/4 - 9) {
11201120
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
11211121
}
11221122
// Should fail in the mul-by-size
@@ -1160,7 +1160,7 @@ fn test_try_reserve_exact() {
11601160
// VecDeque starts with capacity 7, always adds 1 to the capacity
11611161
// and also rounds the number to next power of 2 so this is the
11621162
// furthest we can go without triggering CapacityOverflow
1163-
if let Err(AllocErr(_)) = empty_bytes.try_reserve_exact(MAX_CAP) {
1163+
if let Err(AllocErr) = empty_bytes.try_reserve_exact(MAX_CAP) {
11641164
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
11651165
}
11661166
}
@@ -1179,7 +1179,7 @@ fn test_try_reserve_exact() {
11791179
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
11801180
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
11811181
} else {
1182-
if let Err(AllocErr(_)) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
1182+
if let Err(AllocErr) = ten_bytes.try_reserve_exact(MAX_CAP - 9) {
11831183
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
11841184
}
11851185
if let Err(CapacityOverflow) = ten_bytes.try_reserve_exact(MAX_USIZE) {
@@ -1200,7 +1200,7 @@ fn test_try_reserve_exact() {
12001200
if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) {
12011201
} else { panic!("isize::MAX + 1 should trigger an overflow!"); }
12021202
} else {
1203-
if let Err(AllocErr(_)) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) {
1203+
if let Err(AllocErr) = ten_u32s.try_reserve_exact(MAX_CAP/4 - 9) {
12041204
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
12051205
}
12061206
if let Err(CapacityOverflow) = ten_u32s.try_reserve_exact(MAX_USIZE - 20) {

src/libcore/alloc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,13 @@ pub enum CollectionAllocErr {
356356
/// (usually `isize::MAX` bytes).
357357
CapacityOverflow,
358358
/// Error due to the allocator (see the `AllocErr` type's docs).
359-
AllocErr(AllocErr),
359+
AllocErr,
360360
}
361361

362362
#[unstable(feature = "try_reserve", reason = "new API", issue="48043")]
363363
impl From<AllocErr> for CollectionAllocErr {
364-
fn from(err: AllocErr) -> Self {
365-
CollectionAllocErr::AllocErr(err)
364+
fn from(AllocErr: AllocErr) -> Self {
365+
CollectionAllocErr::AllocErr
366366
}
367367
}
368368

src/libstd/collections/hash/map.rs

Lines changed: 2 additions & 2 deletions
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(_)) => Global.oom(),
787+
Err(CollectionAllocErr::AllocErr) => Global.oom(),
788788
Ok(()) => { /* yay */ }
789789
}
790790
}
@@ -3634,7 +3634,7 @@ mod test_map {
36343634
if let Err(CapacityOverflow) = empty_bytes.try_reserve(max_no_ovf) {
36353635
} else { panic!("isize::MAX + 1 should trigger a CapacityOverflow!") }
36363636
} else {
3637-
if let Err(AllocErr(_)) = empty_bytes.try_reserve(max_no_ovf) {
3637+
if let Err(AllocErr) = empty_bytes.try_reserve(max_no_ovf) {
36383638
} else { panic!("isize::MAX + 1 should trigger an OOM!") }
36393639
}
36403640
}

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(_)) => Global.oom(),
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(_)) => Global.oom(),
814+
Err(CollectionAllocErr::AllocErr) => Global.oom(),
815815
Ok(table) => { table }
816816
}
817817
}

0 commit comments

Comments
 (0)