|
11 | 11 | use self::Entry::*;
|
12 | 12 | use self::VacantEntryState::*;
|
13 | 13 |
|
14 |
| -use std::cell::Cell; |
| 14 | +use rand::{self, Rng}; |
15 | 15 | use std::borrow::Borrow;
|
| 16 | +use std::cell::Cell; |
16 | 17 | use std::cmp::max;
|
17 | 18 | use std::fmt::{self, Debug};
|
18 | 19 | #[allow(deprecated)]
|
19 | 20 | use std::hash::{BuildHasher, Hash, Hasher, SipHasher13};
|
20 | 21 | use std::iter::{FromIterator, FusedIterator};
|
21 | 22 | use std::mem::{self, replace};
|
22 | 23 | use std::ops::{Deref, Index};
|
23 |
| -use rand::{self, Rng}; |
24 | 24 |
|
25 |
| -use super::table::{self, Bucket, EmptyBucket, FullBucket, FullBucketMut, RawTable, SafeHash}; |
26 | 25 | use super::table::BucketState::{Empty, Full};
|
| 26 | +use super::table::{self, Bucket, EmptyBucket, FullBucket, FullBucketMut, RawTable, SafeHash}; |
27 | 27 |
|
28 | 28 | const MIN_NONZERO_RAW_CAPACITY: usize = 32; // must be a power of two
|
29 | 29 |
|
@@ -812,7 +812,8 @@ where
|
812 | 812 | pub fn reserve(&mut self, additional: usize) {
|
813 | 813 | let remaining = self.capacity() - self.len(); // this can't overflow
|
814 | 814 | if remaining < additional {
|
815 |
| - let min_cap = self.len() |
| 815 | + let min_cap = self |
| 816 | + .len() |
816 | 817 | .checked_add(additional)
|
817 | 818 | .expect("reserve overflow");
|
818 | 819 | let raw_cap = self.resize_policy.raw_capacity(min_cap);
|
@@ -2663,11 +2664,11 @@ fn assert_covariance() {
|
2663 | 2664 |
|
2664 | 2665 | #[cfg(test)]
|
2665 | 2666 | mod test_map {
|
2666 |
| - use super::HashMap; |
2667 | 2667 | use super::Entry::{Occupied, Vacant};
|
| 2668 | + use super::HashMap; |
2668 | 2669 | use super::RandomState;
|
2669 |
| - use std::cell::RefCell; |
2670 | 2670 | use rand::{thread_rng, Rng};
|
| 2671 | + use std::cell::RefCell; |
2671 | 2672 |
|
2672 | 2673 | #[test]
|
2673 | 2674 | fn test_zero_capacities() {
|
@@ -3595,7 +3596,6 @@ mod test_map {
|
3595 | 3596 | panic!("Adaptive early resize failed");
|
3596 | 3597 | }
|
3597 | 3598 |
|
3598 |
| - |
3599 | 3599 | #[test]
|
3600 | 3600 | fn test_remove_at_index() {
|
3601 | 3601 | let mut m = HashMap::new();
|
|
0 commit comments