@@ -9,7 +9,7 @@ use rustc_macros::HashStable;
9
9
use rustc_session:: CtfeBacktrace ;
10
10
use rustc_span:: def_id:: DefId ;
11
11
use rustc_target:: abi:: { Align , Size } ;
12
- use std:: { any:: Any , backtrace:: Backtrace , fmt, mem } ;
12
+ use std:: { any:: Any , backtrace:: Backtrace , fmt} ;
13
13
14
14
#[ derive( Debug , Copy , Clone , PartialEq , Eq , HashStable , TyEncodable , TyDecodable ) ]
15
15
pub enum ErrorHandled {
@@ -263,7 +263,7 @@ pub enum UndefinedBehaviorInfo<'tcx> {
263
263
/// Using a string that is not valid UTF-8,
264
264
InvalidStr ( std:: str:: Utf8Error ) ,
265
265
/// Using uninitialized data where it is not allowed.
266
- InvalidUninitBytes ( Option < Box < UninitBytesAccess > > ) ,
266
+ InvalidUninitBytes ( Option < UninitBytesAccess > ) ,
267
267
/// Working with a local that is not currently live.
268
268
DeadLocal ,
269
269
/// Data size is not equal to target size.
@@ -445,7 +445,7 @@ impl dyn MachineStopType {
445
445
}
446
446
447
447
#[ cfg( target_arch = "x86_64" ) ]
448
- static_assert_size ! ( InterpError <' _>, 40 ) ;
448
+ static_assert_size ! ( InterpError <' _>, 72 ) ;
449
449
450
450
pub enum InterpError < ' tcx > {
451
451
/// The program caused undefined behavior.
@@ -486,19 +486,14 @@ impl fmt::Debug for InterpError<'_> {
486
486
}
487
487
488
488
impl InterpError < ' _ > {
489
- /// Some errors allocate to be created as they contain free-form strings .
490
- /// And sometimes we want to be sure that did not happen as it is a
491
- /// waste of resources .
492
- pub fn allocates ( & self ) -> bool {
489
+ /// Some errors to string formatting even if the error is never printed .
490
+ /// To avoid performance issues, there are places where we want to be sure to never raise these formatting errors,
491
+ /// so this method lets us detect them and `bug!` on unexpected errors .
492
+ pub fn formatted_string ( & self ) -> bool {
493
493
match self {
494
- // Zero-sized boxes do not allocate.
495
- InterpError :: MachineStop ( b) => mem:: size_of_val :: < dyn MachineStopType > ( & * * b) > 0 ,
496
494
InterpError :: Unsupported ( UnsupportedOpInfo :: Unsupported ( _) )
497
495
| InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: ValidationFailure ( _) )
498
- | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: Ub ( _) )
499
- | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: InvalidUninitBytes ( Some ( _) ) ) => {
500
- true
501
- }
496
+ | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: Ub ( _) ) => true ,
502
497
_ => false ,
503
498
}
504
499
}
0 commit comments