@@ -58,6 +58,9 @@ pub enum EvalError<'tcx> {
58
58
TypeNotPrimitive ( Ty < ' tcx > ) ,
59
59
ReallocatedStaticMemory ,
60
60
DeallocatedStaticMemory ,
61
+ ReallocateNonBasePtr ,
62
+ DeallocateNonBasePtr ,
63
+ IncorrectAllocationInformation ,
61
64
Layout ( layout:: LayoutError < ' tcx > ) ,
62
65
HeapAllocZeroBytes ,
63
66
HeapAllocNonPowerOfTwoAlignment ( u64 ) ,
@@ -72,98 +75,105 @@ pub type EvalResult<'tcx, T = ()> = Result<T, EvalError<'tcx>>;
72
75
73
76
impl < ' tcx > Error for EvalError < ' tcx > {
74
77
fn description ( & self ) -> & str {
78
+ use EvalError :: * ;
75
79
match * self {
76
- EvalError :: FunctionPointerTyMismatch ( ..) =>
80
+ FunctionPointerTyMismatch ( ..) =>
77
81
"tried to call a function through a function pointer of a different type" ,
78
- EvalError :: InvalidMemoryAccess =>
82
+ InvalidMemoryAccess =>
79
83
"tried to access memory through an invalid pointer" ,
80
- EvalError :: DanglingPointerDeref =>
84
+ DanglingPointerDeref =>
81
85
"dangling pointer was dereferenced" ,
82
- EvalError :: InvalidFunctionPointer =>
86
+ InvalidFunctionPointer =>
83
87
"tried to use an integer pointer or a dangling pointer as a function pointer" ,
84
- EvalError :: InvalidBool =>
88
+ InvalidBool =>
85
89
"invalid boolean value read" ,
86
- EvalError :: InvalidDiscriminant =>
90
+ InvalidDiscriminant =>
87
91
"invalid enum discriminant value read" ,
88
- EvalError :: PointerOutOfBounds { .. } =>
92
+ PointerOutOfBounds { .. } =>
89
93
"pointer offset outside bounds of allocation" ,
90
- EvalError :: InvalidNullPointerUsage =>
94
+ InvalidNullPointerUsage =>
91
95
"invalid use of NULL pointer" ,
92
- EvalError :: ReadPointerAsBytes =>
96
+ ReadPointerAsBytes =>
93
97
"a raw memory access tried to access part of a pointer value as raw bytes" ,
94
- EvalError :: ReadBytesAsPointer =>
98
+ ReadBytesAsPointer =>
95
99
"a memory access tried to interpret some bytes as a pointer" ,
96
- EvalError :: InvalidPointerMath =>
100
+ InvalidPointerMath =>
97
101
"attempted to do invalid arithmetic on pointers that would leak base addresses, e.g. comparing pointers into different allocations" ,
98
- EvalError :: ReadUndefBytes =>
102
+ ReadUndefBytes =>
99
103
"attempted to read undefined bytes" ,
100
- EvalError :: DeadLocal =>
104
+ DeadLocal =>
101
105
"tried to access a dead local variable" ,
102
- EvalError :: InvalidBoolOp ( _) =>
106
+ InvalidBoolOp ( _) =>
103
107
"invalid boolean operation" ,
104
- EvalError :: Unimplemented ( ref msg) => msg,
105
- EvalError :: DerefFunctionPointer =>
108
+ Unimplemented ( ref msg) => msg,
109
+ DerefFunctionPointer =>
106
110
"tried to dereference a function pointer" ,
107
- EvalError :: ExecuteMemory =>
111
+ ExecuteMemory =>
108
112
"tried to treat a memory pointer as a function pointer" ,
109
- EvalError :: ArrayIndexOutOfBounds ( ..) =>
113
+ ArrayIndexOutOfBounds ( ..) =>
110
114
"array index out of bounds" ,
111
- EvalError :: Math ( ..) =>
115
+ Math ( ..) =>
112
116
"mathematical operation failed" ,
113
- EvalError :: Intrinsic ( ..) =>
117
+ Intrinsic ( ..) =>
114
118
"intrinsic failed" ,
115
- EvalError :: OverflowingMath =>
119
+ OverflowingMath =>
116
120
"attempted to do overflowing math" ,
117
- EvalError :: NoMirFor ( ..) =>
121
+ NoMirFor ( ..) =>
118
122
"mir not found" ,
119
- EvalError :: InvalidChar ( ..) =>
123
+ InvalidChar ( ..) =>
120
124
"tried to interpret an invalid 32-bit value as a char" ,
121
- EvalError :: OutOfMemory { ..} =>
125
+ OutOfMemory { ..} =>
122
126
"could not allocate more memory" ,
123
- EvalError :: ExecutionTimeLimitReached =>
127
+ ExecutionTimeLimitReached =>
124
128
"reached the configured maximum execution time" ,
125
- EvalError :: StackFrameLimitReached =>
129
+ StackFrameLimitReached =>
126
130
"reached the configured maximum number of stack frames" ,
127
- EvalError :: OutOfTls =>
131
+ OutOfTls =>
128
132
"reached the maximum number of representable TLS keys" ,
129
- EvalError :: TlsOutOfBounds =>
133
+ TlsOutOfBounds =>
130
134
"accessed an invalid (unallocated) TLS key" ,
131
- EvalError :: AbiViolation ( ref msg) => msg,
132
- EvalError :: AlignmentCheckFailed { ..} =>
135
+ AbiViolation ( ref msg) => msg,
136
+ AlignmentCheckFailed { ..} =>
133
137
"tried to execute a misaligned read or write" ,
134
- EvalError :: CalledClosureAsFunction =>
138
+ CalledClosureAsFunction =>
135
139
"tried to call a closure through a function pointer" ,
136
- EvalError :: VtableForArgumentlessMethod =>
140
+ VtableForArgumentlessMethod =>
137
141
"tried to call a vtable function without arguments" ,
138
- EvalError :: ModifiedConstantMemory =>
142
+ ModifiedConstantMemory =>
139
143
"tried to modify constant memory" ,
140
- EvalError :: AssumptionNotHeld =>
144
+ AssumptionNotHeld =>
141
145
"`assume` argument was false" ,
142
- EvalError :: InlineAsm =>
146
+ InlineAsm =>
143
147
"miri does not support inline assembly" ,
144
- EvalError :: TypeNotPrimitive ( _) =>
148
+ TypeNotPrimitive ( _) =>
145
149
"expected primitive type, got nonprimitive" ,
146
- EvalError :: ReallocatedStaticMemory =>
150
+ ReallocatedStaticMemory =>
147
151
"tried to reallocate static memory" ,
148
- EvalError :: DeallocatedStaticMemory =>
152
+ DeallocatedStaticMemory =>
149
153
"tried to deallocate static memory" ,
150
- EvalError :: Layout ( _) =>
154
+ ReallocateNonBasePtr =>
155
+ "tried to reallocate with a pointer not to the beginning of an existing object" ,
156
+ DeallocateNonBasePtr =>
157
+ "tried to deallocate with a pointer not to the beginning of an existing object" ,
158
+ IncorrectAllocationInformation =>
159
+ "tried to deallocate or reallocate using incorrect alignment or size" ,
160
+ Layout ( _) =>
151
161
"rustc layout computation failed" ,
152
- EvalError :: UnterminatedCString ( _) =>
162
+ UnterminatedCString ( _) =>
153
163
"attempted to get length of a null terminated string, but no null found before end of allocation" ,
154
- EvalError :: HeapAllocZeroBytes =>
164
+ HeapAllocZeroBytes =>
155
165
"tried to re-, de- or allocate zero bytes on the heap" ,
156
- EvalError :: HeapAllocNonPowerOfTwoAlignment ( _) =>
166
+ HeapAllocNonPowerOfTwoAlignment ( _) =>
157
167
"tried to re-, de-, or allocate heap memory with alignment that is not a power of two" ,
158
- EvalError :: Unreachable =>
168
+ Unreachable =>
159
169
"entered unreachable code" ,
160
- EvalError :: Panic =>
170
+ Panic =>
161
171
"the evaluated program panicked" ,
162
- EvalError :: NeedsRfc ( _) =>
172
+ NeedsRfc ( _) =>
163
173
"this feature needs an rfc before being allowed inside constants" ,
164
- EvalError :: NotConst ( _) =>
174
+ NotConst ( _) =>
165
175
"this feature is not compatible with constant evaluation" ,
166
- EvalError :: ReadFromReturnPointer =>
176
+ ReadFromReturnPointer =>
167
177
"tried to read from the return pointer" ,
168
178
}
169
179
}
@@ -173,36 +183,37 @@ impl<'tcx> Error for EvalError<'tcx> {
173
183
174
184
impl < ' tcx > fmt:: Display for EvalError < ' tcx > {
175
185
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
186
+ use EvalError :: * ;
176
187
match * self {
177
- EvalError :: PointerOutOfBounds { ptr, access, allocation_size } => {
188
+ PointerOutOfBounds { ptr, access, allocation_size } => {
178
189
write ! ( f, "{} at offset {}, outside bounds of allocation {} which has size {}" ,
179
190
if access { "memory access" } else { "pointer computed" } ,
180
191
ptr. offset, ptr. alloc_id, allocation_size)
181
192
} ,
182
- EvalError :: NoMirFor ( ref func) => write ! ( f, "no mir for `{}`" , func) ,
183
- EvalError :: FunctionPointerTyMismatch ( sig, got) =>
193
+ NoMirFor ( ref func) => write ! ( f, "no mir for `{}`" , func) ,
194
+ FunctionPointerTyMismatch ( sig, got) =>
184
195
write ! ( f, "tried to call a function with sig {} through a function pointer of type {}" , sig, got) ,
185
- EvalError :: ArrayIndexOutOfBounds ( span, len, index) =>
196
+ ArrayIndexOutOfBounds ( span, len, index) =>
186
197
write ! ( f, "index out of bounds: the len is {} but the index is {} at {:?}" , len, index, span) ,
187
- EvalError :: Math ( span, ref err) =>
198
+ Math ( span, ref err) =>
188
199
write ! ( f, "{:?} at {:?}" , err, span) ,
189
- EvalError :: Intrinsic ( ref err) =>
200
+ Intrinsic ( ref err) =>
190
201
write ! ( f, "{}" , err) ,
191
- EvalError :: InvalidChar ( c) =>
202
+ InvalidChar ( c) =>
192
203
write ! ( f, "tried to interpret an invalid 32-bit value as a char: {}" , c) ,
193
- EvalError :: OutOfMemory { allocation_size, memory_size, memory_usage } =>
204
+ OutOfMemory { allocation_size, memory_size, memory_usage } =>
194
205
write ! ( f, "tried to allocate {} more bytes, but only {} bytes are free of the {} byte memory" ,
195
206
allocation_size, memory_size - memory_usage, memory_size) ,
196
- EvalError :: AlignmentCheckFailed { required, has } =>
207
+ AlignmentCheckFailed { required, has } =>
197
208
write ! ( f, "tried to access memory with alignment {}, but alignment {} is required" ,
198
209
has, required) ,
199
- EvalError :: TypeNotPrimitive ( ty) =>
210
+ TypeNotPrimitive ( ty) =>
200
211
write ! ( f, "expected primitive type, got {}" , ty) ,
201
- EvalError :: Layout ( ref err) =>
212
+ Layout ( ref err) =>
202
213
write ! ( f, "rustc layout computation failed: {:?}" , err) ,
203
- EvalError :: NeedsRfc ( ref msg) =>
214
+ NeedsRfc ( ref msg) =>
204
215
write ! ( f, "\" {}\" needs an rfc before being allowed inside constants" , msg) ,
205
- EvalError :: NotConst ( ref msg) =>
216
+ NotConst ( ref msg) =>
206
217
write ! ( f, "Cannot evaluate within constants: \" {}\" " , msg) ,
207
218
_ => write ! ( f, "{}" , self . description( ) ) ,
208
219
}
0 commit comments