@@ -8044,25 +8044,30 @@ mod test_map {
8044
8044
fn test_try_reserve ( ) {
8045
8045
use crate :: TryReserveError :: { AllocError , CapacityOverflow } ;
8046
8046
8047
- const MAX_USIZE : usize = usize :: MAX ;
8047
+ const MAX_ISIZE : usize = isize :: MAX as usize ;
8048
8048
8049
8049
let mut empty_bytes: HashMap < u8 , u8 > = HashMap :: new ( ) ;
8050
8050
8051
- if let Err ( CapacityOverflow ) = empty_bytes. try_reserve ( MAX_USIZE ) {
8051
+ if let Err ( CapacityOverflow ) = empty_bytes. try_reserve ( usize :: MAX ) {
8052
8052
} else {
8053
8053
panic ! ( "usize::MAX should trigger an overflow!" ) ;
8054
8054
}
8055
8055
8056
- if let Err ( AllocError { .. } ) = empty_bytes. try_reserve ( MAX_USIZE / 16 ) {
8056
+ if let Err ( CapacityOverflow ) = empty_bytes. try_reserve ( MAX_ISIZE ) {
8057
+ } else {
8058
+ panic ! ( "usize::MAX should trigger an overflow!" ) ;
8059
+ }
8060
+
8061
+ if let Err ( AllocError { .. } ) = empty_bytes. try_reserve ( MAX_ISIZE / 16 ) {
8057
8062
} else {
8058
8063
// This may succeed if there is enough free memory. Attempt to
8059
8064
// allocate a few more hashmaps to ensure the allocation will fail.
8060
8065
let mut empty_bytes2: HashMap < u8 , u8 > = HashMap :: new ( ) ;
8061
- let _ = empty_bytes2. try_reserve ( MAX_USIZE / 16 ) ;
8066
+ let _ = empty_bytes2. try_reserve ( MAX_ISIZE / 16 ) ;
8062
8067
let mut empty_bytes3: HashMap < u8 , u8 > = HashMap :: new ( ) ;
8063
- let _ = empty_bytes3. try_reserve ( MAX_USIZE / 16 ) ;
8068
+ let _ = empty_bytes3. try_reserve ( MAX_ISIZE / 16 ) ;
8064
8069
let mut empty_bytes4: HashMap < u8 , u8 > = HashMap :: new ( ) ;
8065
- if let Err ( AllocError { .. } ) = empty_bytes4. try_reserve ( MAX_USIZE / 16 ) {
8070
+ if let Err ( AllocError { .. } ) = empty_bytes4. try_reserve ( MAX_ISIZE / 16 ) {
8066
8071
} else {
8067
8072
panic ! ( "usize::MAX / 8 should trigger an OOM!" ) ;
8068
8073
}
0 commit comments