@@ -245,7 +245,7 @@ fn print_backtrace(backtrace: &mut Backtrace) {
245
245
eprintln ! ( "\n \n An error occurred in miri:\n {:?}" , backtrace) ;
246
246
}
247
247
248
- impl From < ErrorHandled > for InterpErrorInfo < ' tcx > {
248
+ impl From < ErrorHandled > for InterpErrorInfo < ' _ > {
249
249
fn from ( err : ErrorHandled ) -> Self {
250
250
match err {
251
251
ErrorHandled :: Reported => err_inval ! ( ReferencedConstant ) ,
@@ -291,7 +291,7 @@ pub enum InvalidProgramInfo<'tcx> {
291
291
Layout ( layout:: LayoutError < ' tcx > ) ,
292
292
}
293
293
294
- impl fmt:: Debug for InvalidProgramInfo < ' tcx > {
294
+ impl fmt:: Debug for InvalidProgramInfo < ' _ > {
295
295
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
296
296
use InvalidProgramInfo :: * ;
297
297
match self {
@@ -321,6 +321,8 @@ pub enum UndefinedBehaviorInfo {
321
321
RemainderByZero ,
322
322
/// Overflowing inbounds pointer arithmetic.
323
323
PointerArithOverflow ,
324
+ /// Invalid metadata in a wide pointer (using `str` to avoid allocations).
325
+ InvalidMeta ( & ' static str ) ,
324
326
}
325
327
326
328
impl fmt:: Debug for UndefinedBehaviorInfo {
@@ -338,6 +340,7 @@ impl fmt::Debug for UndefinedBehaviorInfo {
338
340
DivisionByZero => write ! ( f, "dividing by zero" ) ,
339
341
RemainderByZero => write ! ( f, "calculating the remainder with a divisor of zero" ) ,
340
342
PointerArithOverflow => write ! ( f, "overflowing in-bounds pointer arithmetic" ) ,
343
+ InvalidMeta ( msg) => write ! ( f, "invalid metadata in wide pointer: {}" , msg) ,
341
344
}
342
345
}
343
346
}
@@ -354,8 +357,8 @@ pub enum UnsupportedOpInfo<'tcx> {
354
357
Unsupported ( String ) ,
355
358
356
359
/// When const-prop encounters a situation it does not support, it raises this error.
357
- /// This must not allocate for performance reasons.
358
- ConstPropUnsupported ( & ' tcx str ) ,
360
+ /// This must not allocate for performance reasons (hence `str`, not `String`) .
361
+ ConstPropUnsupported ( & ' static str ) ,
359
362
360
363
// -- Everything below is not categorized yet --
361
364
FunctionAbiMismatch ( Abi , Abi ) ,
@@ -612,3 +615,19 @@ impl fmt::Debug for InterpError<'_> {
612
615
}
613
616
}
614
617
}
618
+
619
+ impl InterpError < ' _ > {
620
+ /// Some errors allocate to be created as they contain free-form strings.
621
+ /// And sometimes we want to be sure that did not happen as it is a
622
+ /// waste of resources.
623
+ pub fn allocates ( & self ) -> bool {
624
+ match self {
625
+ InterpError :: MachineStop ( _)
626
+ | InterpError :: Unsupported ( UnsupportedOpInfo :: Unsupported ( _) )
627
+ | InterpError :: Unsupported ( UnsupportedOpInfo :: ValidationFailure ( _) )
628
+ | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: Ub ( _) )
629
+ | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: UbExperimental ( _) ) => true ,
630
+ _ => false ,
631
+ }
632
+ }
633
+ }
0 commit comments