@@ -228,6 +228,24 @@ impl<'tcx> From<InterpError<'tcx, u64>> for InterpErrorInfo<'tcx> {
228
228
229
229
pub type AssertMessage < ' tcx > = InterpError < ' tcx , mir:: Operand < ' tcx > > ;
230
230
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
+
231
249
#[ derive( Clone , RustcEncodable , RustcDecodable , HashStable ) ]
232
250
pub enum InterpError < ' tcx , O > {
233
251
/// This variant is used by machines to signal their own errors that do not
@@ -266,11 +284,6 @@ pub enum InterpError<'tcx, O> {
266
284
Unimplemented ( String ) ,
267
285
DerefFunctionPointer ,
268
286
ExecuteMemory ,
269
- BoundsCheck { len : O , index : O } ,
270
- Overflow ( mir:: BinOp ) ,
271
- OverflowNeg ,
272
- DivisionByZero ,
273
- RemainderByZero ,
274
287
Intrinsic ( String ) ,
275
288
InvalidChar ( u128 ) ,
276
289
StackFrameLimitReached ,
@@ -298,12 +311,7 @@ pub enum InterpError<'tcx, O> {
298
311
HeapAllocZeroBytes ,
299
312
HeapAllocNonPowerOfTwoAlignment ( u64 ) ,
300
313
Unreachable ,
301
- Panic {
302
- msg : Symbol ,
303
- line : u32 ,
304
- col : u32 ,
305
- file : Symbol ,
306
- } ,
314
+ Panic ( PanicMessage < O > ) ,
307
315
ReadFromReturnPointer ,
308
316
PathNotFound ( Vec < String > ) ,
309
317
UnimplementedTraitSelection ,
@@ -369,8 +377,6 @@ impl<'tcx, O> InterpError<'tcx, O> {
369
377
"tried to dereference a function pointer" ,
370
378
ExecuteMemory =>
371
379
"tried to treat a memory pointer as a function pointer" ,
372
- BoundsCheck { ..} =>
373
- "array index out of bounds" ,
374
380
Intrinsic ( ..) =>
375
381
"intrinsic failed" ,
376
382
NoMirFor ( ..) =>
@@ -422,8 +428,32 @@ impl<'tcx, O> InterpError<'tcx, O> {
422
428
two",
423
429
Unreachable =>
424
430
"entered unreachable code" ,
425
- Panic { .. } =>
431
+ Panic ( PanicMessage :: Panic { .. } ) =>
426
432
"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" ,
427
457
ReadFromReturnPointer =>
428
458
"tried to read from the return pointer" ,
429
459
PathNotFound ( _) =>
@@ -436,17 +466,6 @@ impl<'tcx, O> InterpError<'tcx, O> {
436
466
"encountered overly generic constant" ,
437
467
ReferencedConstant =>
438
468
"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" ,
450
469
GeneratorResumedAfterReturn => "generator resumed after completion" ,
451
470
GeneratorResumedAfterPanic => "generator resumed after panicking" ,
452
471
InfiniteLoop =>
@@ -493,8 +512,6 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
493
512
callee_ty, caller_ty) ,
494
513
FunctionArgCountMismatch =>
495
514
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) ,
498
515
ReallocatedWrongMemoryKind ( ref old, ref new) =>
499
516
write ! ( f, "tried to reallocate memory from {} to {}" , old, new) ,
500
517
DeallocatedWrongMemoryKind ( ref old, ref new) =>
@@ -518,8 +535,10 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
518
535
write ! ( f, "incorrect alloc info: expected size {} and align {}, \
519
536
got size {} and align {}",
520
537
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 } ) =>
522
539
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) ,
523
542
InvalidDiscriminant ( val) =>
524
543
write ! ( f, "encountered invalid enum discriminant {}" , val) ,
525
544
Exit ( code) =>
0 commit comments