@@ -1489,12 +1489,6 @@ fn test_try_reserve() {
14891489 const MAX_CAP : usize = isize:: MAX as usize ;
14901490 const MAX_USIZE : usize = usize:: MAX ;
14911491
1492- // On 16/32-bit, we check that allocations don't exceed isize::MAX,
1493- // on 64-bit, we assume the OS will give an OOM for such a ridiculous size.
1494- // Any platform that succeeds for these requests is technically broken with
1495- // ptr::offset because LLVM is the worst.
1496- let guards_against_isize = usize:: BITS < 64 ;
1497-
14981492 {
14991493 // Note: basic stuff is checked by test_reserve
15001494 let mut empty_bytes: Vec < u8 > = Vec :: new ( ) ;
@@ -1508,35 +1502,19 @@ fn test_try_reserve() {
15081502 panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
15091503 }
15101504
1511- if guards_against_isize {
1512- // Check isize::MAX + 1 does count as overflow
1513- assert_matches ! (
1514- empty_bytes. try_reserve( MAX_CAP + 1 ) . map_err( |e| e. kind( ) ) ,
1515- Err ( CapacityOverflow ) ,
1516- "isize::MAX + 1 should trigger an overflow!"
1517- ) ;
1518-
1519- // Check usize::MAX does count as overflow
1520- assert_matches ! (
1521- empty_bytes. try_reserve( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1522- Err ( CapacityOverflow ) ,
1523- "usize::MAX should trigger an overflow!"
1524- ) ;
1525- } else {
1526- // Check isize::MAX + 1 is an OOM
1527- assert_matches ! (
1528- empty_bytes. try_reserve( MAX_CAP + 1 ) . map_err( |e| e. kind( ) ) ,
1529- Err ( AllocError { .. } ) ,
1530- "isize::MAX + 1 should trigger an OOM!"
1531- ) ;
1532-
1533- // Check usize::MAX is an OOM
1534- assert_matches ! (
1535- empty_bytes. try_reserve( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1536- Err ( AllocError { .. } ) ,
1537- "usize::MAX should trigger an OOM!"
1538- ) ;
1539- }
1505+ // Check isize::MAX + 1 does count as overflow
1506+ assert_matches ! (
1507+ empty_bytes. try_reserve( MAX_CAP + 1 ) . map_err( |e| e. kind( ) ) ,
1508+ Err ( CapacityOverflow ) ,
1509+ "isize::MAX + 1 should trigger an overflow!"
1510+ ) ;
1511+
1512+ // Check usize::MAX does count as overflow
1513+ assert_matches ! (
1514+ empty_bytes. try_reserve( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1515+ Err ( CapacityOverflow ) ,
1516+ "usize::MAX should trigger an overflow!"
1517+ ) ;
15401518 }
15411519
15421520 {
@@ -1549,19 +1527,13 @@ fn test_try_reserve() {
15491527 if let Err ( CapacityOverflow ) = ten_bytes. try_reserve ( MAX_CAP - 10 ) . map_err ( |e| e. kind ( ) ) {
15501528 panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
15511529 }
1552- if guards_against_isize {
1553- assert_matches ! (
1554- ten_bytes. try_reserve( MAX_CAP - 9 ) . map_err( |e| e. kind( ) ) ,
1555- Err ( CapacityOverflow ) ,
1556- "isize::MAX + 1 should trigger an overflow!"
1557- ) ;
1558- } else {
1559- assert_matches ! (
1560- ten_bytes. try_reserve( MAX_CAP - 9 ) . map_err( |e| e. kind( ) ) ,
1561- Err ( AllocError { .. } ) ,
1562- "isize::MAX + 1 should trigger an OOM!"
1563- ) ;
1564- }
1530+
1531+ assert_matches ! (
1532+ ten_bytes. try_reserve( MAX_CAP - 9 ) . map_err( |e| e. kind( ) ) ,
1533+ Err ( CapacityOverflow ) ,
1534+ "isize::MAX + 1 should trigger an overflow!"
1535+ ) ;
1536+
15651537 // Should always overflow in the add-to-len
15661538 assert_matches ! (
15671539 ten_bytes. try_reserve( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
@@ -1582,19 +1554,13 @@ fn test_try_reserve() {
15821554 {
15831555 panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
15841556 }
1585- if guards_against_isize {
1586- assert_matches ! (
1587- ten_u32s. try_reserve( MAX_CAP / 4 - 9 ) . map_err( |e| e. kind( ) ) ,
1588- Err ( CapacityOverflow ) ,
1589- "isize::MAX + 1 should trigger an overflow!"
1590- ) ;
1591- } else {
1592- assert_matches ! (
1593- ten_u32s. try_reserve( MAX_CAP / 4 - 9 ) . map_err( |e| e. kind( ) ) ,
1594- Err ( AllocError { .. } ) ,
1595- "isize::MAX + 1 should trigger an OOM!"
1596- ) ;
1597- }
1557+
1558+ assert_matches ! (
1559+ ten_u32s. try_reserve( MAX_CAP / 4 - 9 ) . map_err( |e| e. kind( ) ) ,
1560+ Err ( CapacityOverflow ) ,
1561+ "isize::MAX + 1 should trigger an overflow!"
1562+ ) ;
1563+
15981564 // Should fail in the mul-by-size
15991565 assert_matches ! (
16001566 ten_u32s. try_reserve( MAX_USIZE - 20 ) . map_err( |e| e. kind( ) ) ,
@@ -1614,8 +1580,6 @@ fn test_try_reserve_exact() {
16141580 const MAX_CAP : usize = isize:: MAX as usize ;
16151581 const MAX_USIZE : usize = usize:: MAX ;
16161582
1617- let guards_against_isize = size_of :: < usize > ( ) < 8 ;
1618-
16191583 {
16201584 let mut empty_bytes: Vec < u8 > = Vec :: new ( ) ;
16211585
@@ -1628,31 +1592,17 @@ fn test_try_reserve_exact() {
16281592 panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
16291593 }
16301594
1631- if guards_against_isize {
1632- assert_matches ! (
1633- empty_bytes. try_reserve_exact( MAX_CAP + 1 ) . map_err( |e| e. kind( ) ) ,
1634- Err ( CapacityOverflow ) ,
1635- "isize::MAX + 1 should trigger an overflow!"
1636- ) ;
1637-
1638- assert_matches ! (
1639- empty_bytes. try_reserve_exact( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1640- Err ( CapacityOverflow ) ,
1641- "usize::MAX should trigger an overflow!"
1642- ) ;
1643- } else {
1644- assert_matches ! (
1645- empty_bytes. try_reserve_exact( MAX_CAP + 1 ) . map_err( |e| e. kind( ) ) ,
1646- Err ( AllocError { .. } ) ,
1647- "isize::MAX + 1 should trigger an OOM!"
1648- ) ;
1649-
1650- assert_matches ! (
1651- empty_bytes. try_reserve_exact( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1652- Err ( AllocError { .. } ) ,
1653- "usize::MAX should trigger an OOM!"
1654- ) ;
1655- }
1595+ assert_matches ! (
1596+ empty_bytes. try_reserve_exact( MAX_CAP + 1 ) . map_err( |e| e. kind( ) ) ,
1597+ Err ( CapacityOverflow ) ,
1598+ "isize::MAX + 1 should trigger an overflow!"
1599+ ) ;
1600+
1601+ assert_matches ! (
1602+ empty_bytes. try_reserve_exact( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1603+ Err ( CapacityOverflow ) ,
1604+ "usize::MAX should trigger an overflow!"
1605+ ) ;
16561606 }
16571607
16581608 {
@@ -1668,19 +1618,13 @@ fn test_try_reserve_exact() {
16681618 {
16691619 panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
16701620 }
1671- if guards_against_isize {
1672- assert_matches ! (
1673- ten_bytes. try_reserve_exact( MAX_CAP - 9 ) . map_err( |e| e. kind( ) ) ,
1674- Err ( CapacityOverflow ) ,
1675- "isize::MAX + 1 should trigger an overflow!"
1676- ) ;
1677- } else {
1678- assert_matches ! (
1679- ten_bytes. try_reserve_exact( MAX_CAP - 9 ) . map_err( |e| e. kind( ) ) ,
1680- Err ( AllocError { .. } ) ,
1681- "isize::MAX + 1 should trigger an OOM!"
1682- ) ;
1683- }
1621+
1622+ assert_matches ! (
1623+ ten_bytes. try_reserve_exact( MAX_CAP - 9 ) . map_err( |e| e. kind( ) ) ,
1624+ Err ( CapacityOverflow ) ,
1625+ "isize::MAX + 1 should trigger an overflow!"
1626+ ) ;
1627+
16841628 assert_matches ! (
16851629 ten_bytes. try_reserve_exact( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
16861630 Err ( CapacityOverflow ) ,
@@ -1701,19 +1645,13 @@ fn test_try_reserve_exact() {
17011645 {
17021646 panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
17031647 }
1704- if guards_against_isize {
1705- assert_matches ! (
1706- ten_u32s. try_reserve_exact( MAX_CAP / 4 - 9 ) . map_err( |e| e. kind( ) ) ,
1707- Err ( CapacityOverflow ) ,
1708- "isize::MAX + 1 should trigger an overflow!"
1709- ) ;
1710- } else {
1711- assert_matches ! (
1712- ten_u32s. try_reserve_exact( MAX_CAP / 4 - 9 ) . map_err( |e| e. kind( ) ) ,
1713- Err ( AllocError { .. } ) ,
1714- "isize::MAX + 1 should trigger an OOM!"
1715- ) ;
1716- }
1648+
1649+ assert_matches ! (
1650+ ten_u32s. try_reserve_exact( MAX_CAP / 4 - 9 ) . map_err( |e| e. kind( ) ) ,
1651+ Err ( CapacityOverflow ) ,
1652+ "isize::MAX + 1 should trigger an overflow!"
1653+ ) ;
1654+
17171655 assert_matches ! (
17181656 ten_u32s. try_reserve_exact( MAX_USIZE - 20 ) . map_err( |e| e. kind( ) ) ,
17191657 Err ( CapacityOverflow ) ,
0 commit comments