@@ -8,7 +8,6 @@ use super::{
8
8
MemoryPointer , Lock , AccessKind
9
9
} ;
10
10
11
- use rustc_const_math:: ConstMathErr ;
12
11
use syntax:: codemap:: Span ;
13
12
use backtrace:: Backtrace ;
14
13
@@ -304,3 +303,41 @@ impl<'tcx> fmt::Display for EvalError<'tcx> {
304
303
}
305
304
}
306
305
}
306
+
307
+ #[ derive( Debug , PartialEq , Eq , Clone , RustcEncodable , RustcDecodable ) ]
308
+ pub enum ConstMathErr {
309
+ Overflow ( Op ) ,
310
+ DivisionByZero ,
311
+ RemainderByZero ,
312
+ }
313
+ pub use self :: ConstMathErr :: * ;
314
+
315
+ #[ derive( Debug , PartialEq , Eq , Clone , RustcEncodable , RustcDecodable ) ]
316
+ pub enum Op {
317
+ Add ,
318
+ Sub ,
319
+ Mul ,
320
+ Div ,
321
+ Rem ,
322
+ Shr ,
323
+ Shl ,
324
+ Neg ,
325
+ }
326
+
327
+ impl ConstMathErr {
328
+ pub fn description ( & self ) -> & ' static str {
329
+ use self :: Op :: * ;
330
+ match * self {
331
+ Overflow ( Add ) => "attempt to add with overflow" ,
332
+ Overflow ( Sub ) => "attempt to subtract with overflow" ,
333
+ Overflow ( Mul ) => "attempt to multiply with overflow" ,
334
+ Overflow ( Div ) => "attempt to divide with overflow" ,
335
+ Overflow ( Rem ) => "attempt to calculate the remainder with overflow" ,
336
+ Overflow ( Neg ) => "attempt to negate with overflow" ,
337
+ Overflow ( Shr ) => "attempt to shift right with overflow" ,
338
+ Overflow ( Shl ) => "attempt to shift left with overflow" ,
339
+ DivisionByZero => "attempt to divide by zero" ,
340
+ RemainderByZero => "attempt to calculate the remainder with a divisor of zero" ,
341
+ }
342
+ }
343
+ }
0 commit comments