@@ -1244,10 +1244,10 @@ pub enum TerminatorKind<'tcx> {
12441244#[ derive( Clone , RustcEncodable , RustcDecodable , HashStable , PartialEq ) ]
12451245pub enum AssertKind < O > {
12461246 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 ) ,
12511251 ResumedAfterReturn ( GeneratorKind ) ,
12521252 ResumedAfterPanic ( GeneratorKind ) ,
12531253}
@@ -1520,17 +1520,17 @@ impl<O> AssertKind<O> {
15201520 pub fn description ( & self ) -> & ' static str {
15211521 use AssertKind :: * ;
15221522 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" ,
15341534 ResumedAfterReturn ( GeneratorKind :: Gen ) => "generator resumed after completion" ,
15351535 ResumedAfterReturn ( GeneratorKind :: Async ( _) ) => "`async fn` resumed after completion" ,
15361536 ResumedAfterPanic ( GeneratorKind :: Gen ) => "generator resumed after panicking" ,
@@ -1544,12 +1544,54 @@ impl<O> AssertKind<O> {
15441544 where
15451545 O : Debug ,
15461546 {
1547+ use AssertKind :: * ;
15471548 match self {
1548- AssertKind :: BoundsCheck { ref len, ref index } => write ! (
1549+ BoundsCheck { ref len, ref index } => write ! (
15491550 f,
15501551 "\" index out of bounds: the len is {{}} but the index is {{}}\" , {:?}, {:?}" ,
15511552 len, index
15521553 ) ,
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+ }
15531595 _ => write ! ( f, "\" {}\" " , self . description( ) ) ,
15541596 }
15551597 }
@@ -1562,6 +1604,34 @@ impl<O: fmt::Debug> fmt::Debug for AssertKind<O> {
15621604 BoundsCheck { ref len, ref index } => {
15631605 write ! ( f, "index out of bounds: the len is {:?} but the index is {:?}" , len, index)
15641606 }
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+ }
15651635 _ => write ! ( f, "{}" , self . description( ) ) ,
15661636 }
15671637 }
0 commit comments