- UnimplementedTraitSelection,
- /// Abort in case type errors are reached
- TypeckError,
- /// Resolution can fail if we are in a too generic context
- TooGeneric,
- /// Cannot compute this constant because it depends on another one
- /// which already produced an error
- ReferencedConstant,
- GeneratorResumedAfterReturn,
- GeneratorResumedAfterPanic,
- InfiniteLoop,
-}
-
-pub type InterpResult<'tcx, T = ()> = Result<T, InterpErrorInfo<'tcx>>;
-
-impl<'tcx, O> InterpError<'tcx, O> {
- pub fn description(&self) -> &str {
- use self::InterpError::*;
- match *self {
- MachineError(ref inner) => inner,
- Exit(..) =>
- "exited",
- FunctionAbiMismatch(..) | FunctionArgMismatch(..) | FunctionRetMismatch(..)
- | FunctionArgCountMismatch =>
- "tried to call a function through a function pointer of incompatible type",
- InvalidMemoryAccess =>
- "tried to access memory through an invalid pointer",
- DanglingPointerDeref =>
- "dangling pointer was dereferenced",
- DoubleFree =>
- "tried to deallocate dangling pointer",
- InvalidFunctionPointer =>
- "tried to use a function pointer after offsetting it",
- InvalidBool =>
- "invalid boolean value read",
- InvalidDiscriminant(..) =>
- "invalid enum discriminant value read",
- PointerOutOfBounds { .. } =>
- "pointer offset outside bounds of allocation",
- InvalidNullPointerUsage =>
- "invalid use of NULL pointer",
- ValidationFailure(..) =>
- "type validation failed",
- ReadPointerAsBytes =>
- "a raw memory access tried to access part of a pointer value as raw bytes",
- ReadBytesAsPointer =>
- "a memory access tried to interpret some bytes as a pointer",
- ReadForeignStatic =>
- "tried to read from foreign (extern) static",
- InvalidPointerMath =>
- "attempted to do invalid arithmetic on pointers that would leak base addresses, \
- e.g., comparing pointers into different allocations",
- ReadUndefBytes(_) =>
- "attempted to read undefined bytes",
- DeadLocal =>
- "tried to access a dead local variable",
- InvalidBoolOp(_) =>
- "invalid boolean operation",
- Unimplemented(ref msg) => msg,
- DerefFunctionPointer =>
- "tried to dereference a function pointer",
- ExecuteMemory =>
- "tried to treat a memory pointer as a function pointer",
- Intrinsic(..) =>
- "intrinsic failed",
- NoMirFor(..) =>
- "mir not found",
- InvalidChar(..) =>
- "tried to interpret an invalid 32-bit value as a char",
- StackFrameLimitReached =>
- "reached the configured maximum number of stack frames",
- OutOfTls =>
- "reached the maximum number of representable TLS keys",
- TlsOutOfBounds =>
- "accessed an invalid (unallocated) TLS key",
- AbiViolation(ref msg) => msg,
- AlignmentCheckFailed{..} =>
- "tried to execute a misaligned read or write",
- CalledClosureAsFunction =>
- "tried to call a closure through a function pointer",
- VtableForArgumentlessMethod =>
- "tried to call a vtable function without arguments",
- ModifiedConstantMemory =>
- "tried to modify constant memory",
- ModifiedStatic =>
- "tried to modify a static's initial value from another static's initializer",
- AssumptionNotHeld =>
- "`assume` argument was false",
- InlineAsm =>
- "miri does not support inline assembly",
- TypeNotPrimitive(_) =>
- "expected primitive type, got nonprimitive",
- ReallocatedWrongMemoryKind(_, _) =>
- "tried to reallocate memory from one kind to another",
- DeallocatedWrongMemoryKind(_, _) =>
- "tried to deallocate memory of the wrong kind",
- ReallocateNonBasePtr =>
- "tried to reallocate with a pointer not to the beginning of an existing object",
- DeallocateNonBasePtr =>
- "tried to deallocate with a pointer not to the beginning of an existing object",
- IncorrectAllocationInformation(..) =>
- "tried to deallocate or reallocate using incorrect alignment or size",
- Layout(_) =>
- "rustc layout computation failed",
- UnterminatedCString(_) =>
- "attempted to get length of a null terminated string, but no null found before end \
- of allocation",
- HeapAllocZeroBytes =>
- "tried to re-, de- or allocate zero bytes on the heap",
- HeapAllocNonPowerOfTwoAlignment(_) =>
- "tried to re-, de-, or allocate heap memory with alignment that is not a power of \
- two",
- Unreachable =>
- "entered unreachable code",
- Panic(PanicMessage::Panic{..}) =>
- "the evaluated program panicked",
- Panic(PanicMessage::BoundsCheck{..}) =>
- "array index out of bounds",
- Panic(PanicMessage::Overflow(mir::BinOp::Add)) =>
- "attempt to add with overflow",
- Panic(PanicMessage::Overflow(mir::BinOp::Sub)) =>
- "attempt to subtract with overflow",
- Panic(PanicMessage::Overflow(mir::BinOp::Mul)) =>
- "attempt to multiply with overflow",
- Panic(PanicMessage::Overflow(mir::BinOp::Div)) =>
- "attempt to divide with overflow",
- Panic(PanicMessage::Overflow(mir::BinOp::Rem)) =>
- "attempt to calculate the remainder with overflow",
- Panic(PanicMessage::OverflowNeg) =>
- "attempt to negate with overflow",
- Panic(PanicMessage::Overflow(mir::BinOp::Shr)) =>
- "attempt to shift right with overflow",
- Panic(PanicMessage::Overflow(mir::BinOp::Shl)) =>
- "attempt to shift left with overflow",
- Panic(PanicMessage::Overflow(op)) =>
- bug!("{:?} cannot overflow", op),
- Panic(PanicMessage::DivisionByZero) =>
- "attempt to divide by zero",
- Panic(PanicMessage::RemainderByZero) =>
- "attempt to calculate the remainder with a divisor of zero",
- ReadFromReturnPointer =>
- "tried to read from the return pointer",
- PathNotFound(_) =>
- "a path could not be resolved, maybe the crate is not loaded",
- UnimplementedTraitSelection =>
- "there were unresolved type arguments during trait selection",
- TypeckError =>
- "encountered constants with type errors, stopping evaluation",
- TooGeneric =>
- "encountered overly generic constant",
- ReferencedConstant =>
- "referenced constant has errors",
- GeneratorResumedAfterReturn => "generator resumed after completion",
- GeneratorResumedAfterPanic => "generator resumed after panicking",
- InfiniteLoop =>
- "duplicate interpreter state observed here, const evaluation will never terminate",
- }
- }
-}
-
-impl<'tcx> fmt::Display for InterpErrorInfo<'tcx> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{}", self.kind)
- }
-}
-
-impl<'tcx> fmt::Display for InterpError<'tcx, u64> {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{:?}", self)
- }