@@ -1489,12 +1489,6 @@ fn test_try_reserve() {
1489
1489
const MAX_CAP : usize = isize:: MAX as usize ;
1490
1490
const MAX_USIZE : usize = usize:: MAX ;
1491
1491
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
-
1498
1492
{
1499
1493
// Note: basic stuff is checked by test_reserve
1500
1494
let mut empty_bytes: Vec < u8 > = Vec :: new ( ) ;
@@ -1508,35 +1502,19 @@ fn test_try_reserve() {
1508
1502
panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
1509
1503
}
1510
1504
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
+ ) ;
1540
1518
}
1541
1519
1542
1520
{
@@ -1549,19 +1527,13 @@ fn test_try_reserve() {
1549
1527
if let Err ( CapacityOverflow ) = ten_bytes. try_reserve ( MAX_CAP - 10 ) . map_err ( |e| e. kind ( ) ) {
1550
1528
panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
1551
1529
}
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
+
1565
1537
// Should always overflow in the add-to-len
1566
1538
assert_matches ! (
1567
1539
ten_bytes. try_reserve( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
@@ -1582,19 +1554,13 @@ fn test_try_reserve() {
1582
1554
{
1583
1555
panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
1584
1556
}
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
+
1598
1564
// Should fail in the mul-by-size
1599
1565
assert_matches ! (
1600
1566
ten_u32s. try_reserve( MAX_USIZE - 20 ) . map_err( |e| e. kind( ) ) ,
@@ -1614,8 +1580,6 @@ fn test_try_reserve_exact() {
1614
1580
const MAX_CAP : usize = isize:: MAX as usize ;
1615
1581
const MAX_USIZE : usize = usize:: MAX ;
1616
1582
1617
- let guards_against_isize = size_of :: < usize > ( ) < 8 ;
1618
-
1619
1583
{
1620
1584
let mut empty_bytes: Vec < u8 > = Vec :: new ( ) ;
1621
1585
@@ -1628,31 +1592,17 @@ fn test_try_reserve_exact() {
1628
1592
panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
1629
1593
}
1630
1594
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
+ ) ;
1656
1606
}
1657
1607
1658
1608
{
@@ -1668,19 +1618,13 @@ fn test_try_reserve_exact() {
1668
1618
{
1669
1619
panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
1670
1620
}
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
+
1684
1628
assert_matches ! (
1685
1629
ten_bytes. try_reserve_exact( MAX_USIZE ) . map_err( |e| e. kind( ) ) ,
1686
1630
Err ( CapacityOverflow ) ,
@@ -1701,19 +1645,13 @@ fn test_try_reserve_exact() {
1701
1645
{
1702
1646
panic ! ( "isize::MAX shouldn't trigger an overflow!" ) ;
1703
1647
}
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
+
1717
1655
assert_matches ! (
1718
1656
ten_u32s. try_reserve_exact( MAX_USIZE - 20 ) . map_err( |e| e. kind( ) ) ,
1719
1657
Err ( CapacityOverflow ) ,
0 commit comments