@@ -1244,10 +1244,10 @@ pub enum TerminatorKind<'tcx> {
1244
1244
#[ derive( Clone , RustcEncodable , RustcDecodable , HashStable , PartialEq ) ]
1245
1245
pub enum AssertKind < O > {
1246
1246
BoundsCheck { len : O , index : O } ,
1247
- Overflow ( BinOp ) ,
1248
- OverflowNeg ,
1249
- DivisionByZero ,
1250
- RemainderByZero ,
1247
+ Overflow ( BinOp , O , O ) ,
1248
+ OverflowNeg ( O ) ,
1249
+ DivisionByZero ( O ) ,
1250
+ RemainderByZero ( O ) ,
1251
1251
ResumedAfterReturn ( GeneratorKind ) ,
1252
1252
ResumedAfterPanic ( GeneratorKind ) ,
1253
1253
}
@@ -1520,17 +1520,17 @@ impl<O> AssertKind<O> {
1520
1520
pub fn description ( & self ) -> & ' static str {
1521
1521
use AssertKind :: * ;
1522
1522
match self {
1523
- Overflow ( BinOp :: Add ) => "attempt to add with overflow" ,
1524
- Overflow ( BinOp :: Sub ) => "attempt to subtract with overflow" ,
1525
- Overflow ( BinOp :: Mul ) => "attempt to multiply with overflow" ,
1526
- Overflow ( BinOp :: Div ) => "attempt to divide with overflow" ,
1527
- Overflow ( BinOp :: Rem ) => "attempt to calculate the remainder with overflow" ,
1528
- OverflowNeg => "attempt to negate with overflow" ,
1529
- Overflow ( BinOp :: Shr ) => "attempt to shift right with overflow" ,
1530
- Overflow ( BinOp :: Shl ) => "attempt to shift left with overflow" ,
1531
- Overflow ( op) => bug ! ( "{:?} cannot overflow" , op) ,
1532
- DivisionByZero => "attempt to divide by zero" ,
1533
- RemainderByZero => "attempt to calculate the remainder with a divisor of zero" ,
1523
+ Overflow ( BinOp :: Add , _ , _ ) => "attempt to add with overflow" ,
1524
+ Overflow ( BinOp :: Sub , _ , _ ) => "attempt to subtract with overflow" ,
1525
+ Overflow ( BinOp :: Mul , _ , _ ) => "attempt to multiply with overflow" ,
1526
+ Overflow ( BinOp :: Div , _ , _ ) => "attempt to divide with overflow" ,
1527
+ Overflow ( BinOp :: Rem , _ , _ ) => "attempt to calculate the remainder with overflow" ,
1528
+ OverflowNeg ( _ ) => "attempt to negate with overflow" ,
1529
+ Overflow ( BinOp :: Shr , _ , _ ) => "attempt to shift right with overflow" ,
1530
+ Overflow ( BinOp :: Shl , _ , _ ) => "attempt to shift left with overflow" ,
1531
+ Overflow ( op, _ , _ ) => bug ! ( "{:?} cannot overflow" , op) ,
1532
+ DivisionByZero ( _ ) => "attempt to divide by zero" ,
1533
+ RemainderByZero ( _ ) => "attempt to calculate the remainder with a divisor of zero" ,
1534
1534
ResumedAfterReturn ( GeneratorKind :: Gen ) => "generator resumed after completion" ,
1535
1535
ResumedAfterReturn ( GeneratorKind :: Async ( _) ) => "`async fn` resumed after completion" ,
1536
1536
ResumedAfterPanic ( GeneratorKind :: Gen ) => "generator resumed after panicking" ,
@@ -1544,12 +1544,54 @@ impl<O> AssertKind<O> {
1544
1544
where
1545
1545
O : Debug ,
1546
1546
{
1547
+ use AssertKind :: * ;
1547
1548
match self {
1548
- AssertKind :: BoundsCheck { ref len, ref index } => write ! (
1549
+ BoundsCheck { ref len, ref index } => write ! (
1549
1550
f,
1550
1551
"\" index out of bounds: the len is {{}} but the index is {{}}\" , {:?}, {:?}" ,
1551
1552
len, index
1552
1553
) ,
1554
+
1555
+ OverflowNeg ( op) => {
1556
+ write ! ( f, "\" attempt to negate {{}} which would overflow\" , {:?}" , op)
1557
+ }
1558
+ DivisionByZero ( op) => write ! ( f, "\" attempt to divide {{}} by zero\" , {:?}" , op) ,
1559
+ RemainderByZero ( op) => write ! (
1560
+ f,
1561
+ "\" attempt to calculate the remainder of {{}} with a divisor of zero\" , {:?}" ,
1562
+ op
1563
+ ) ,
1564
+ Overflow ( BinOp :: Add , l, r) => write ! (
1565
+ f,
1566
+ "\" attempt to compute `{{}} + {{}}` which would overflow\" , {:?}, {:?}" ,
1567
+ l, r
1568
+ ) ,
1569
+ Overflow ( BinOp :: Sub , l, r) => write ! (
1570
+ f,
1571
+ "\" attempt to compute `{{}} - {{}}` which would overflow\" , {:?}, {:?}" ,
1572
+ l, r
1573
+ ) ,
1574
+ Overflow ( BinOp :: Mul , l, r) => write ! (
1575
+ f,
1576
+ "\" attempt to compute `{{}} * {{}}` which would overflow\" , {:?}, {:?}" ,
1577
+ l, r
1578
+ ) ,
1579
+ Overflow ( BinOp :: Div , l, r) => write ! (
1580
+ f,
1581
+ "\" attempt to compute `{{}} / {{}}` which would overflow\" , {:?}, {:?}" ,
1582
+ l, r
1583
+ ) ,
1584
+ Overflow ( BinOp :: Rem , l, r) => write ! (
1585
+ f,
1586
+ "\" attempt to compute the remainder of `{{}} % {{}}` which would overflow\" , {:?}, {:?}" ,
1587
+ l, r
1588
+ ) ,
1589
+ Overflow ( BinOp :: Shr , _, r) => {
1590
+ write ! ( f, "\" attempt to shift right by {{}} which would overflow\" , {:?}" , r)
1591
+ }
1592
+ Overflow ( BinOp :: Shl , _, r) => {
1593
+ write ! ( f, "\" attempt to shift left by {{}} which would overflow\" , {:?}" , r)
1594
+ }
1553
1595
_ => write ! ( f, "\" {}\" " , self . description( ) ) ,
1554
1596
}
1555
1597
}
@@ -1562,6 +1604,34 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
1562
1604
BoundsCheck { ref len, ref index } => {
1563
1605
write ! ( f, "index out of bounds: the len is {:?} but the index is {:?}" , len, index)
1564
1606
}
1607
+ OverflowNeg ( op) => write ! ( f, "attempt to negate {:#?} which would overflow" , op) ,
1608
+ DivisionByZero ( op) => write ! ( f, "attempt to divide {:#?} by zero" , op) ,
1609
+ RemainderByZero ( op) => {
1610
+ write ! ( f, "attempt to calculate the remainder of {:#?} with a divisor of zero" , op)
1611
+ }
1612
+ Overflow ( BinOp :: Add , l, r) => {
1613
+ write ! ( f, "attempt to compute `{:#?} + {:#?}` which would overflow" , l, r)
1614
+ }
1615
+ Overflow ( BinOp :: Sub , l, r) => {
1616
+ write ! ( f, "attempt to compute `{:#?} - {:#?}` which would overflow" , l, r)
1617
+ }
1618
+ Overflow ( BinOp :: Mul , l, r) => {
1619
+ write ! ( f, "attempt to compute `{:#?} * {:#?}` which would overflow" , l, r)
1620
+ }
1621
+ Overflow ( BinOp :: Div , l, r) => {
1622
+ write ! ( f, "attempt to compute `{:#?} / {:#?}` which would overflow" , l, r)
1623
+ }
1624
+ Overflow ( BinOp :: Rem , l, r) => write ! (
1625
+ f,
1626
+ "attempt to compute the remainder of `{:#?} % {:#?}` which would overflow" ,
1627
+ l, r
1628
+ ) ,
1629
+ Overflow ( BinOp :: Shr , _, r) => {
1630
+ write ! ( f, "attempt to shift right by {:#?} which would overflow" , r)
1631
+ }
1632
+ Overflow ( BinOp :: Shl , _, r) => {
1633
+ write ! ( f, "attempt to shift left by {:#?} which would overflow" , r)
1634
+ }
1565
1635
_ => write ! ( f, "{}" , self . description( ) ) ,
1566
1636
}
1567
1637
}
0 commit comments