@@ -8044,25 +8044,30 @@ mod test_map {
80448044 fn test_try_reserve ( ) {
80458045 use crate :: TryReserveError :: { AllocError , CapacityOverflow } ;
80468046
8047- const MAX_USIZE : usize = usize :: MAX ;
8047+ const MAX_ISIZE : usize = isize :: MAX as usize ;
80488048
80498049 let mut empty_bytes: HashMap < u8 , u8 > = HashMap :: new ( ) ;
80508050
8051- if let Err ( CapacityOverflow ) = empty_bytes. try_reserve ( MAX_USIZE ) {
8051+ if let Err ( CapacityOverflow ) = empty_bytes. try_reserve ( usize :: MAX ) {
80528052 } else {
80538053 panic ! ( "usize::MAX should trigger an overflow!" ) ;
80548054 }
80558055
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 ) {
80578062 } else {
80588063 // This may succeed if there is enough free memory. Attempt to
80598064 // allocate a few more hashmaps to ensure the allocation will fail.
80608065 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 ) ;
80628067 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 ) ;
80648069 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 ) {
80668071 } else {
80678072 panic ! ( "usize::MAX / 8 should trigger an OOM!" ) ;
80688073 }
0 commit comments