@@ -228,6 +228,24 @@ impl<'tcx> From<InterpError<'tcx, u64>> for InterpErrorInfo<'tcx> {
228228
229229pub type AssertMessage < ' tcx > = InterpError < ' tcx , mir:: Operand < ' tcx > > ;
230230
231+ #[ derive( Clone , RustcEncodable , RustcDecodable , HashStable ) ]
232+ pub enum PanicMessage < O > {
233+ Panic {
234+ msg : Symbol ,
235+ line : u32 ,
236+ col : u32 ,
237+ file : Symbol ,
238+ } ,
239+ BoundsCheck {
240+ len : O ,
241+ index : O ,
242+ } ,
243+ Overflow ( mir:: BinOp ) ,
244+ OverflowNeg ,
245+ DivisionByZero ,
246+ RemainderByZero ,
247+ }
248+
231249#[ derive( Clone , RustcEncodable , RustcDecodable , HashStable ) ]
232250pub enum InterpError < ' tcx , O > {
233251 /// This variant is used by machines to signal their own errors that do not
@@ -266,11 +284,6 @@ pub enum InterpError<'tcx, O> {
266284 Unimplemented ( String ) ,
267285 DerefFunctionPointer ,
268286 ExecuteMemory ,
269- BoundsCheck { len : O , index : O } ,
270- Overflow ( mir:: BinOp ) ,
271- OverflowNeg ,
272- DivisionByZero ,
273- RemainderByZero ,
274287 Intrinsic ( String ) ,
275288 InvalidChar ( u128 ) ,
276289 StackFrameLimitReached ,
@@ -298,12 +311,7 @@ pub enum InterpError<'tcx, O> {
298311 HeapAllocZeroBytes ,
299312 HeapAllocNonPowerOfTwoAlignment ( u64 ) ,
300313 Unreachable ,
301- Panic {
302- msg : Symbol ,
303- line : u32 ,
304- col : u32 ,
305- file : Symbol ,
306- } ,
314+ Panic ( PanicMessage < O > ) ,
307315 ReadFromReturnPointer ,
308316 PathNotFound ( Vec < String > ) ,
309317 UnimplementedTraitSelection ,
@@ -369,8 +377,6 @@ impl<'tcx, O> InterpError<'tcx, O> {
369377 "tried to dereference a function pointer" ,
370378 ExecuteMemory =>
371379 "tried to treat a memory pointer as a function pointer" ,
372- BoundsCheck { ..} =>
373- "array index out of bounds" ,
374380 Intrinsic ( ..) =>
375381 "intrinsic failed" ,
376382 NoMirFor ( ..) =>
@@ -422,8 +428,32 @@ impl<'tcx, O> InterpError<'tcx, O> {
422428 two",
423429 Unreachable =>
424430 "entered unreachable code" ,
425- Panic { .. } =>
431+ Panic ( PanicMessage :: Panic { .. } ) =>
426432 "the evaluated program panicked" ,
433+ Panic ( PanicMessage :: BoundsCheck { ..} ) =>
434+ "array index out of bounds" ,
435+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Add ) ) =>
436+ "attempt to add with overflow" ,
437+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Sub ) ) =>
438+ "attempt to subtract with overflow" ,
439+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Mul ) ) =>
440+ "attempt to multiply with overflow" ,
441+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Div ) ) =>
442+ "attempt to divide with overflow" ,
443+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Rem ) ) =>
444+ "attempt to calculate the remainder with overflow" ,
445+ Panic ( PanicMessage :: OverflowNeg ) =>
446+ "attempt to negate with overflow" ,
447+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Shr ) ) =>
448+ "attempt to shift right with overflow" ,
449+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Shl ) ) =>
450+ "attempt to shift left with overflow" ,
451+ Panic ( PanicMessage :: Overflow ( op) ) =>
452+ bug ! ( "{:?} cannot overflow" , op) ,
453+ Panic ( PanicMessage :: DivisionByZero ) =>
454+ "attempt to divide by zero" ,
455+ Panic ( PanicMessage :: RemainderByZero ) =>
456+ "attempt to calculate the remainder with a divisor of zero" ,
427457 ReadFromReturnPointer =>
428458 "tried to read from the return pointer" ,
429459 PathNotFound ( _) =>
@@ -436,17 +466,6 @@ impl<'tcx, O> InterpError<'tcx, O> {
436466 "encountered overly generic constant" ,
437467 ReferencedConstant =>
438468 "referenced constant has errors" ,
439- Overflow ( mir:: BinOp :: Add ) => "attempt to add with overflow" ,
440- Overflow ( mir:: BinOp :: Sub ) => "attempt to subtract with overflow" ,
441- Overflow ( mir:: BinOp :: Mul ) => "attempt to multiply with overflow" ,
442- Overflow ( mir:: BinOp :: Div ) => "attempt to divide with overflow" ,
443- Overflow ( mir:: BinOp :: Rem ) => "attempt to calculate the remainder with overflow" ,
444- OverflowNeg => "attempt to negate with overflow" ,
445- Overflow ( mir:: BinOp :: Shr ) => "attempt to shift right with overflow" ,
446- Overflow ( mir:: BinOp :: Shl ) => "attempt to shift left with overflow" ,
447- Overflow ( op) => bug ! ( "{:?} cannot overflow" , op) ,
448- DivisionByZero => "attempt to divide by zero" ,
449- RemainderByZero => "attempt to calculate the remainder with a divisor of zero" ,
450469 GeneratorResumedAfterReturn => "generator resumed after completion" ,
451470 GeneratorResumedAfterPanic => "generator resumed after panicking" ,
452471 InfiniteLoop =>
@@ -493,8 +512,6 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
493512 callee_ty, caller_ty) ,
494513 FunctionArgCountMismatch =>
495514 write ! ( f, "tried to call a function with incorrect number of arguments" ) ,
496- BoundsCheck { ref len, ref index } =>
497- write ! ( f, "index out of bounds: the len is {:?} but the index is {:?}" , len, index) ,
498515 ReallocatedWrongMemoryKind ( ref old, ref new) =>
499516 write ! ( f, "tried to reallocate memory from {} to {}" , old, new) ,
500517 DeallocatedWrongMemoryKind ( ref old, ref new) =>
@@ -518,8 +535,10 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
518535 write ! ( f, "incorrect alloc info: expected size {} and align {}, \
519536 got size {} and align {}",
520537 size. bytes( ) , align. bytes( ) , size2. bytes( ) , align2. bytes( ) ) ,
521- Panic { ref msg, line, col, ref file } =>
538+ Panic ( PanicMessage :: Panic { ref msg, line, col, ref file } ) =>
522539 write ! ( f, "the evaluated program panicked at '{}', {}:{}:{}" , msg, file, line, col) ,
540+ Panic ( PanicMessage :: BoundsCheck { ref len, ref index } ) =>
541+ write ! ( f, "index out of bounds: the len is {:?} but the index is {:?}" , len, index) ,
523542 InvalidDiscriminant ( val) =>
524543 write ! ( f, "encountered invalid enum discriminant {}" , val) ,
525544 Exit ( code) =>
0 commit comments