Skip to content

Commit 95062a0

Browse files
committed
Fix test_try_reserve
1 parent 6be4f48 commit 95062a0

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

src/map.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,7 +2543,6 @@ mod test_map {
25432543
use super::HashMap;
25442544
use rand::{thread_rng, Rng};
25452545
use std::cell::RefCell;
2546-
use std::mem::size_of;
25472546
use std::usize;
25482547
use std::vec::Vec;
25492548
use CollectionAllocErr::*;
@@ -3406,30 +3405,14 @@ mod test_map {
34063405

34073406
const MAX_USIZE: usize = usize::MAX;
34083407

3409-
// HashMap and RawTables use complicated size calculations
3410-
// hashes_size is sizeof(u8) * capacity;
3411-
// pairs_size is sizeof((K. V)) * capacity;
3412-
// alignment_hashes_size is 8
3413-
// alignment_pairs size is 4
3414-
let size_of_multiplier = (size_of::<u8>() + size_of::<(u8, u8)>()).next_power_of_two();
3415-
// The following formula is used to calculate the new capacity
3416-
let max_no_ovf = ((MAX_USIZE / 8) * 7) / size_of_multiplier - 1;
3417-
34183408
if let Err(CapacityOverflow) = empty_bytes.try_reserve(MAX_USIZE) {
34193409
} else {
34203410
panic!("usize::MAX should trigger an overflow!");
34213411
}
34223412

3423-
if size_of::<usize>() < 8 {
3424-
if let Err(CapacityOverflow) = empty_bytes.try_reserve(max_no_ovf) {
3425-
} else {
3426-
panic!("isize::MAX + 1 should trigger a CapacityOverflow!")
3427-
}
3413+
if let Err(AllocErr) = empty_bytes.try_reserve(MAX_USIZE / 8) {
34283414
} else {
3429-
if let Err(AllocErr) = empty_bytes.try_reserve(max_no_ovf) {
3430-
} else {
3431-
panic!("isize::MAX + 1 should trigger an OOM!")
3432-
}
3415+
panic!("usize::MAX / 8 should trigger an OOM!")
34333416
}
34343417
}
34353418

0 commit comments

Comments
 (0)