22//!
33//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html
44
5+ // ignore-tidy-filelength
6+
57use crate :: mir:: interpret:: { GlobalAlloc , Scalar } ;
68use crate :: mir:: visit:: MirVisitable ;
79use crate :: ty:: adjustment:: PointerCast ;
@@ -1246,10 +1248,10 @@ pub enum TerminatorKind<'tcx> {
12461248#[ derive( Clone , RustcEncodable , RustcDecodable , HashStable , PartialEq ) ]
12471249pub enum AssertKind < O > {
12481250 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 ) ,
12531255 ResumedAfterReturn ( GeneratorKind ) ,
12541256 ResumedAfterPanic ( GeneratorKind ) ,
12551257}
@@ -1522,17 +1524,17 @@ impl<O> AssertKind<O> {
15221524 pub fn description ( & self ) -> & ' static str {
15231525 use AssertKind :: * ;
15241526 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" ,
15361538 ResumedAfterReturn ( GeneratorKind :: Gen ) => "generator resumed after completion" ,
15371539 ResumedAfterReturn ( GeneratorKind :: Async ( _) ) => "`async fn` resumed after completion" ,
15381540 ResumedAfterPanic ( GeneratorKind :: Gen ) => "generator resumed after panicking" ,
@@ -1546,12 +1548,54 @@ impl<O> AssertKind<O> {
15461548 where
15471549 O : Debug ,
15481550 {
1551+ use AssertKind :: * ;
15491552 match self {
1550- AssertKind :: BoundsCheck { ref len, ref index } => write ! (
1553+ BoundsCheck { ref len, ref index } => write ! (
15511554 f,
15521555 "\" index out of bounds: the len is {{}} but the index is {{}}\" , {:?}, {:?}" ,
15531556 len, index
15541557 ) ,
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+ }
15551599 _ => write ! ( f, "\" {}\" " , self . description( ) ) ,
15561600 }
15571601 }
@@ -1564,6 +1608,34 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
15641608 BoundsCheck { ref len, ref index } => {
15651609 write ! ( f, "index out of bounds: the len is {:?} but the index is {:?}" , len, index)
15661610 }
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+ }
15671639 _ => write ! ( f, "{}" , self . description( ) ) ,
15681640 }
15691641 }
0 commit comments