@@ -9,7 +9,7 @@ use rustc_macros::HashStable;
99use rustc_session:: CtfeBacktrace ;
1010use rustc_span:: def_id:: DefId ;
1111use rustc_target:: abi:: { Align , Size } ;
12- use std:: { any:: Any , backtrace:: Backtrace , fmt, mem } ;
12+ use std:: { any:: Any , backtrace:: Backtrace , fmt} ;
1313
1414#[ derive( Debug , Copy , Clone , PartialEq , Eq , HashStable , TyEncodable , TyDecodable ) ]
1515pub enum ErrorHandled {
@@ -263,7 +263,7 @@ pub enum UndefinedBehaviorInfo<'tcx> {
263263 /// Using a string that is not valid UTF-8,
264264 InvalidStr ( std:: str:: Utf8Error ) ,
265265 /// Using uninitialized data where it is not allowed.
266- InvalidUninitBytes ( Option < Box < UninitBytesAccess > > ) ,
266+ InvalidUninitBytes ( Option < UninitBytesAccess > ) ,
267267 /// Working with a local that is not currently live.
268268 DeadLocal ,
269269 /// Data size is not equal to target size.
@@ -445,7 +445,7 @@ impl dyn MachineStopType {
445445}
446446
447447#[ cfg( target_arch = "x86_64" ) ]
448- static_assert_size ! ( InterpError <' _>, 40 ) ;
448+ static_assert_size ! ( InterpError <' _>, 72 ) ;
449449
450450pub enum InterpError < ' tcx > {
451451 /// The program caused undefined behavior.
@@ -486,19 +486,14 @@ impl fmt::Debug for InterpError<'_> {
486486}
487487
488488impl 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 {
493493 match self {
494- // Zero-sized boxes do not allocate.
495- InterpError :: MachineStop ( b) => mem:: size_of_val :: < dyn MachineStopType > ( & * * b) > 0 ,
496494 InterpError :: Unsupported ( UnsupportedOpInfo :: Unsupported ( _) )
497495 | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: ValidationFailure ( _) )
498- | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: Ub ( _) )
499- | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: InvalidUninitBytes ( Some ( _) ) ) => {
500- true
501- }
496+ | InterpError :: UndefinedBehavior ( UndefinedBehaviorInfo :: Ub ( _) ) => true ,
502497 _ => false ,
503498 }
504499 }
0 commit comments