@@ -329,151 +329,6 @@ pub enum InterpError<'tcx, O> {
329329
330330pub type InterpResult < ' tcx , T = ( ) > = Result < T , InterpErrorInfo < ' tcx > > ;
331331
332- impl < ' tcx , O > InterpError < ' tcx , O > {
333- pub ( crate ) fn description ( & self ) -> & str {
334- use self :: InterpError :: * ;
335- match * self {
336- MachineError ( ref inner) => inner,
337- Exit ( ..) =>
338- "exited" ,
339- FunctionAbiMismatch ( ..) | FunctionArgMismatch ( ..) | FunctionRetMismatch ( ..)
340- | FunctionArgCountMismatch =>
341- "tried to call a function through a function pointer of incompatible type" ,
342- InvalidMemoryAccess =>
343- "tried to access memory through an invalid pointer" ,
344- DanglingPointerDeref =>
345- "dangling pointer was dereferenced" ,
346- DoubleFree =>
347- "tried to deallocate dangling pointer" ,
348- InvalidFunctionPointer =>
349- "tried to use a function pointer after offsetting it" ,
350- InvalidBool =>
351- "invalid boolean value read" ,
352- InvalidDiscriminant ( ..) =>
353- "invalid enum discriminant value read" ,
354- PointerOutOfBounds { .. } =>
355- "pointer offset outside bounds of allocation" ,
356- InvalidNullPointerUsage =>
357- "invalid use of NULL pointer" ,
358- ValidationFailure ( ..) =>
359- "type validation failed" ,
360- ReadPointerAsBytes =>
361- "a raw memory access tried to access part of a pointer value as raw bytes" ,
362- ReadBytesAsPointer =>
363- "a memory access tried to interpret some bytes as a pointer" ,
364- ReadForeignStatic =>
365- "tried to read from foreign (extern) static" ,
366- InvalidPointerMath =>
367- "attempted to do invalid arithmetic on pointers that would leak base addresses, \
368- e.g., comparing pointers into different allocations",
369- ReadUndefBytes ( _) =>
370- "attempted to read undefined bytes" ,
371- DeadLocal =>
372- "tried to access a dead local variable" ,
373- InvalidBoolOp ( _) =>
374- "invalid boolean operation" ,
375- Unimplemented ( ref msg) => msg,
376- DerefFunctionPointer =>
377- "tried to dereference a function pointer" ,
378- ExecuteMemory =>
379- "tried to treat a memory pointer as a function pointer" ,
380- Intrinsic ( ..) =>
381- "intrinsic failed" ,
382- NoMirFor ( ..) =>
383- "mir not found" ,
384- InvalidChar ( ..) =>
385- "tried to interpret an invalid 32-bit value as a char" ,
386- StackFrameLimitReached =>
387- "reached the configured maximum number of stack frames" ,
388- OutOfTls =>
389- "reached the maximum number of representable TLS keys" ,
390- TlsOutOfBounds =>
391- "accessed an invalid (unallocated) TLS key" ,
392- AbiViolation ( ref msg) => msg,
393- AlignmentCheckFailed { ..} =>
394- "tried to execute a misaligned read or write" ,
395- CalledClosureAsFunction =>
396- "tried to call a closure through a function pointer" ,
397- VtableForArgumentlessMethod =>
398- "tried to call a vtable function without arguments" ,
399- ModifiedConstantMemory =>
400- "tried to modify constant memory" ,
401- ModifiedStatic =>
402- "tried to modify a static's initial value from another static's initializer" ,
403- AssumptionNotHeld =>
404- "`assume` argument was false" ,
405- InlineAsm =>
406- "miri does not support inline assembly" ,
407- TypeNotPrimitive ( _) =>
408- "expected primitive type, got nonprimitive" ,
409- ReallocatedWrongMemoryKind ( _, _) =>
410- "tried to reallocate memory from one kind to another" ,
411- DeallocatedWrongMemoryKind ( _, _) =>
412- "tried to deallocate memory of the wrong kind" ,
413- ReallocateNonBasePtr =>
414- "tried to reallocate with a pointer not to the beginning of an existing object" ,
415- DeallocateNonBasePtr =>
416- "tried to deallocate with a pointer not to the beginning of an existing object" ,
417- IncorrectAllocationInformation ( ..) =>
418- "tried to deallocate or reallocate using incorrect alignment or size" ,
419- Layout ( _) =>
420- "rustc layout computation failed" ,
421- UnterminatedCString ( _) =>
422- "attempted to get length of a null terminated string, but no null found before end \
423- of allocation",
424- HeapAllocZeroBytes =>
425- "tried to re-, de- or allocate zero bytes on the heap" ,
426- HeapAllocNonPowerOfTwoAlignment ( _) =>
427- "tried to re-, de-, or allocate heap memory with alignment that is not a power of \
428- two",
429- Unreachable =>
430- "entered unreachable code" ,
431- Panic ( PanicMessage :: Panic { ..} ) =>
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" ,
457- ReadFromReturnPointer =>
458- "tried to read from the return pointer" ,
459- PathNotFound ( _) =>
460- "a path could not be resolved, maybe the crate is not loaded" ,
461- UnimplementedTraitSelection =>
462- "there were unresolved type arguments during trait selection" ,
463- TypeckError =>
464- "encountered constants with type errors, stopping evaluation" ,
465- TooGeneric =>
466- "encountered overly generic constant" ,
467- ReferencedConstant =>
468- "referenced constant has errors" ,
469- GeneratorResumedAfterReturn => "generator resumed after completion" ,
470- GeneratorResumedAfterPanic => "generator resumed after panicking" ,
471- InfiniteLoop =>
472- "duplicate interpreter state observed here, const evaluation will never terminate" ,
473- }
474- }
475- }
476-
477332impl < ' tcx > fmt:: Display for InterpErrorInfo < ' tcx > {
478333 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
479334 write ! ( f, "{}" , self . kind)
@@ -516,8 +371,6 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
516371 write ! ( f, "tried to reallocate memory from {} to {}" , old, new) ,
517372 DeallocatedWrongMemoryKind ( ref old, ref new) =>
518373 write ! ( f, "tried to deallocate {} memory but gave {} as the kind" , old, new) ,
519- Intrinsic ( ref err) =>
520- write ! ( f, "{}" , err) ,
521374 InvalidChar ( c) =>
522375 write ! ( f, "tried to interpret an invalid 32-bit value as a char: {}" , c) ,
523376 AlignmentCheckFailed { required, has } =>
@@ -529,21 +382,130 @@ impl<'tcx, O: fmt::Debug> fmt::Debug for InterpError<'tcx, O> {
529382 write ! ( f, "rustc layout computation failed: {:?}" , err) ,
530383 PathNotFound ( ref path) =>
531384 write ! ( f, "Cannot find path {:?}" , path) ,
532- MachineError ( ref inner) =>
533- write ! ( f, "{}" , inner) ,
534385 IncorrectAllocationInformation ( size, size2, align, align2) =>
535386 write ! ( f, "incorrect alloc info: expected size {} and align {}, \
536387 got size {} and align {}",
537388 size. bytes( ) , align. bytes( ) , size2. bytes( ) , align2. bytes( ) ) ,
538- Panic ( PanicMessage :: Panic { ref msg, line, col, ref file } ) =>
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) ,
542389 InvalidDiscriminant ( val) =>
543390 write ! ( f, "encountered invalid enum discriminant {}" , val) ,
544391 Exit ( code) =>
545392 write ! ( f, "exited with status code {}" , code) ,
546- _ => write ! ( f, "{}" , self . description( ) ) ,
393+ InvalidMemoryAccess =>
394+ write ! ( f, "tried to access memory through an invalid pointer" ) ,
395+ DanglingPointerDeref =>
396+ write ! ( f, "dangling pointer was dereferenced" ) ,
397+ DoubleFree =>
398+ write ! ( f, "tried to deallocate dangling pointer" ) ,
399+ InvalidFunctionPointer =>
400+ write ! ( f, "tried to use a function pointer after offsetting it" ) ,
401+ InvalidBool =>
402+ write ! ( f, "invalid boolean value read" ) ,
403+ InvalidNullPointerUsage =>
404+ write ! ( f, "invalid use of NULL pointer" ) ,
405+ ReadPointerAsBytes =>
406+ write ! ( f, "a raw memory access tried to access part of a pointer value as raw \
407+ bytes") ,
408+ ReadBytesAsPointer =>
409+ write ! ( f, "a memory access tried to interpret some bytes as a pointer" ) ,
410+ ReadForeignStatic =>
411+ write ! ( f, "tried to read from foreign (extern) static" ) ,
412+ InvalidPointerMath =>
413+ write ! ( f, "attempted to do invalid arithmetic on pointers that would leak base \
414+ addresses, e.g., comparing pointers into different allocations") ,
415+ DeadLocal =>
416+ write ! ( f, "tried to access a dead local variable" ) ,
417+ DerefFunctionPointer =>
418+ write ! ( f, "tried to dereference a function pointer" ) ,
419+ ExecuteMemory =>
420+ write ! ( f, "tried to treat a memory pointer as a function pointer" ) ,
421+ StackFrameLimitReached =>
422+ write ! ( f, "reached the configured maximum number of stack frames" ) ,
423+ OutOfTls =>
424+ write ! ( f, "reached the maximum number of representable TLS keys" ) ,
425+ TlsOutOfBounds =>
426+ write ! ( f, "accessed an invalid (unallocated) TLS key" ) ,
427+ CalledClosureAsFunction =>
428+ write ! ( f, "tried to call a closure through a function pointer" ) ,
429+ VtableForArgumentlessMethod =>
430+ write ! ( f, "tried to call a vtable function without arguments" ) ,
431+ ModifiedConstantMemory =>
432+ write ! ( f, "tried to modify constant memory" ) ,
433+ ModifiedStatic =>
434+ write ! ( f, "tried to modify a static's initial value from another static's \
435+ initializer") ,
436+ AssumptionNotHeld =>
437+ write ! ( f, "`assume` argument was false" ) ,
438+ InlineAsm =>
439+ write ! ( f, "miri does not support inline assembly" ) ,
440+ ReallocateNonBasePtr =>
441+ write ! ( f, "tried to reallocate with a pointer not to the beginning of an \
442+ existing object") ,
443+ DeallocateNonBasePtr =>
444+ write ! ( f, "tried to deallocate with a pointer not to the beginning of an \
445+ existing object") ,
446+ HeapAllocZeroBytes =>
447+ write ! ( f, "tried to re-, de- or allocate zero bytes on the heap" ) ,
448+ Unreachable =>
449+ write ! ( f, "entered unreachable code" ) ,
450+ ReadFromReturnPointer =>
451+ write ! ( f, "tried to read from the return pointer" ) ,
452+ UnimplementedTraitSelection =>
453+ write ! ( f, "there were unresolved type arguments during trait selection" ) ,
454+ TypeckError =>
455+ write ! ( f, "encountered constants with type errors, stopping evaluation" ) ,
456+ TooGeneric =>
457+ write ! ( f, "encountered overly generic constant" ) ,
458+ ReferencedConstant =>
459+ write ! ( f, "referenced constant has errors" ) ,
460+ GeneratorResumedAfterReturn =>
461+ write ! ( f, "generator resumed after completion" ) ,
462+ GeneratorResumedAfterPanic =>
463+ write ! ( f, "generator resumed after panicking" ) ,
464+ InfiniteLoop =>
465+ write ! ( f, "duplicate interpreter state observed here, const evaluation will never \
466+ terminate") ,
467+ InvalidBoolOp ( _) =>
468+ write ! ( f, "invalid boolean operation" ) ,
469+ UnterminatedCString ( _) =>
470+ write ! ( f, "attempted to get length of a null terminated string, but no null \
471+ found before end of allocation") ,
472+ ReadUndefBytes ( _) =>
473+ write ! ( f, "attempted to read undefined bytes" ) ,
474+ HeapAllocNonPowerOfTwoAlignment ( _) =>
475+ write ! ( f, "tried to re-, de-, or allocate heap memory with alignment that is \
476+ not a power of two") ,
477+ MachineError ( ref msg) |
478+ Unimplemented ( ref msg) |
479+ AbiViolation ( ref msg) |
480+ Intrinsic ( ref msg) =>
481+ write ! ( f, "{}" , msg) ,
482+
483+ Panic ( PanicMessage :: Panic { ref msg, line, col, ref file } ) =>
484+ write ! ( f, "the evaluated program panicked at '{}', {}:{}:{}" , msg, file, line, col) ,
485+ Panic ( PanicMessage :: BoundsCheck { ref len, ref index } ) =>
486+ write ! ( f, "index out of bounds: the len is {:?} but the index is {:?}" , len, index) ,
487+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Add ) ) =>
488+ write ! ( f, "attempt to add with overflow" ) ,
489+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Sub ) ) =>
490+ write ! ( f, "attempt to subtract with overflow" ) ,
491+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Mul ) ) =>
492+ write ! ( f, "attempt to multiply with overflow" ) ,
493+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Div ) ) =>
494+ write ! ( f, "attempt to divide with overflow" ) ,
495+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Rem ) ) =>
496+ write ! ( f, "attempt to calculate the remainder with overflow" ) ,
497+ Panic ( PanicMessage :: OverflowNeg ) =>
498+ write ! ( f, "attempt to negate with overflow" ) ,
499+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Shr ) ) =>
500+ write ! ( f, "attempt to shift right with overflow" ) ,
501+ Panic ( PanicMessage :: Overflow ( mir:: BinOp :: Shl ) ) =>
502+ write ! ( f, "attempt to shift left with overflow" ) ,
503+ Panic ( PanicMessage :: Overflow ( op) ) =>
504+ bug ! ( "{:?} cannot overflow" , op) ,
505+ Panic ( PanicMessage :: DivisionByZero ) =>
506+ write ! ( f, "attempt to divide by zero" ) ,
507+ Panic ( PanicMessage :: RemainderByZero ) =>
508+ write ! ( f, "attempt to calculate the remainder with a divisor of zero" ) ,
547509 }
548510 }
549511}
0 commit comments