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