@@ -285,7 +285,7 @@ pub enum InvalidProgramInfo<'tcx> {
285
285
TransmuteSizeDiff ( Ty < ' tcx > , Ty < ' tcx > ) ,
286
286
}
287
287
288
- impl fmt:: Debug for InvalidProgramInfo < ' _ > {
288
+ impl fmt:: Display for InvalidProgramInfo < ' _ > {
289
289
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
290
290
use InvalidProgramInfo :: * ;
291
291
match self {
@@ -310,8 +310,6 @@ pub enum UndefinedBehaviorInfo {
310
310
Ub ( String ) ,
311
311
/// Unreachable code was executed.
312
312
Unreachable ,
313
- /// An enum discriminant was set to a value which was outside the range of valid values.
314
- InvalidDiscriminant ( ScalarMaybeUndef ) ,
315
313
/// A slice/array index projection went out-of-bounds.
316
314
BoundsCheckFailed {
317
315
len : u64 ,
@@ -356,6 +354,8 @@ pub enum UndefinedBehaviorInfo {
356
354
InvalidBool ( u8 ) ,
357
355
/// Using a non-character `u32` as character.
358
356
InvalidChar ( u32 ) ,
357
+ /// An enum discriminant was set to a value which was outside the range of valid values.
358
+ InvalidDiscriminant ( ScalarMaybeUndef ) ,
359
359
/// Using uninitialized data where it is not allowed.
360
360
InvalidUndefBytes ( Option < Pointer > ) ,
361
361
/// Working with a local that is not currently live.
@@ -367,29 +367,26 @@ pub enum UndefinedBehaviorInfo {
367
367
} ,
368
368
}
369
369
370
- impl fmt:: Debug for UndefinedBehaviorInfo {
370
+ impl fmt:: Display for UndefinedBehaviorInfo {
371
371
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
372
372
use UndefinedBehaviorInfo :: * ;
373
373
match self {
374
374
Ub ( msg) => write ! ( f, "{}" , msg) ,
375
375
Unreachable => write ! ( f, "entering unreachable code" ) ,
376
- InvalidDiscriminant ( val) => write ! ( f, "encountering invalid enum discriminant {}" , val) ,
377
- BoundsCheckFailed { ref len, ref index } => write ! (
378
- f,
379
- "indexing out of bounds: the len is {:?} but the index is {:?}" ,
380
- len, index
381
- ) ,
376
+ BoundsCheckFailed { ref len, ref index } => {
377
+ write ! ( f, "indexing out of bounds: the len is {} but the index is {}" , len, index)
378
+ }
382
379
DivisionByZero => write ! ( f, "dividing by zero" ) ,
383
380
RemainderByZero => write ! ( f, "calculating the remainder with a divisor of zero" ) ,
384
381
PointerArithOverflow => write ! ( f, "overflowing in-bounds pointer arithmetic" ) ,
385
382
InvalidMeta ( msg) => write ! ( f, "invalid metadata in wide pointer: {}" , msg) ,
386
383
UnterminatedCString ( p) => write ! (
387
384
f,
388
- "reading a null-terminated string starting at {:? } with no null found before end of allocation" ,
385
+ "reading a null-terminated string starting at {} with no null found before end of allocation" ,
389
386
p,
390
387
) ,
391
388
PointerUseAfterFree ( a) => {
392
- write ! ( f, "pointer to {:? } was dereferenced after this allocation got freed" , a)
389
+ write ! ( f, "pointer to {} was dereferenced after this allocation got freed" , a)
393
390
}
394
391
PointerOutOfBounds { ptr, msg, allocation_size } => write ! (
395
392
f,
@@ -408,17 +405,18 @@ impl fmt::Debug for UndefinedBehaviorInfo {
408
405
has. bytes( ) ,
409
406
required. bytes( )
410
407
) ,
411
- WriteToReadOnly ( a) => write ! ( f, "writing to {:? } which is read-only" , a) ,
408
+ WriteToReadOnly ( a) => write ! ( f, "writing to {} which is read-only" , a) ,
412
409
InvalidFunctionPointer ( p) => {
413
- write ! ( f, "using {:? } as function pointer but it does not point to a function" , p)
410
+ write ! ( f, "using {} as function pointer but it does not point to a function" , p)
414
411
}
415
- DerefFunctionPointer ( a) => write ! ( f, "accessing {:? } which contains a function" , a) ,
412
+ DerefFunctionPointer ( a) => write ! ( f, "accessing {} which contains a function" , a) ,
416
413
ValidationFailure ( ref err) => write ! ( f, "type validation failed: {}" , err) ,
417
414
InvalidBool ( b) => write ! ( f, "interpreting an invalid 8-bit value as a bool: {}" , b) ,
418
415
InvalidChar ( c) => write ! ( f, "interpreting an invalid 32-bit value as a char: {}" , c) ,
416
+ InvalidDiscriminant ( val) => write ! ( f, "enum value has invalid discriminant: {}" , val) ,
419
417
InvalidUndefBytes ( Some ( p) ) => write ! (
420
418
f,
421
- "reading uninitialized memory at {:? }, but this operation requires initialized memory" ,
419
+ "reading uninitialized memory at {}, but this operation requires initialized memory" ,
422
420
p
423
421
) ,
424
422
InvalidUndefBytes ( None ) => write ! (
@@ -455,7 +453,7 @@ pub enum UnsupportedOpInfo {
455
453
ReadBytesAsPointer ,
456
454
}
457
455
458
- impl fmt:: Debug for UnsupportedOpInfo {
456
+ impl fmt:: Display for UnsupportedOpInfo {
459
457
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
460
458
use UnsupportedOpInfo :: * ;
461
459
match self {
@@ -481,7 +479,7 @@ pub enum ResourceExhaustionInfo {
481
479
StepLimitReached ,
482
480
}
483
481
484
- impl fmt:: Debug for ResourceExhaustionInfo {
482
+ impl fmt:: Display for ResourceExhaustionInfo {
485
483
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
486
484
use ResourceExhaustionInfo :: * ;
487
485
match self {
@@ -499,7 +497,6 @@ impl fmt::Debug for ResourceExhaustionInfo {
499
497
pub trait AsAny : Any {
500
498
fn as_any ( & self ) -> & dyn Any ;
501
499
}
502
-
503
500
impl < T : Any > AsAny for T {
504
501
#[ inline( always) ]
505
502
fn as_any ( & self ) -> & dyn Any {
@@ -508,7 +505,7 @@ impl<T: Any> AsAny for T {
508
505
}
509
506
510
507
/// A trait for machine-specific errors (or other "machine stop" conditions).
511
- pub trait MachineStopType : AsAny + fmt:: Debug + Send { }
508
+ pub trait MachineStopType : AsAny + fmt:: Display + Send { }
512
509
impl MachineStopType for String { }
513
510
514
511
impl dyn MachineStopType {
@@ -538,21 +535,21 @@ pub type InterpResult<'tcx, T = ()> = Result<T, InterpErrorInfo<'tcx>>;
538
535
539
536
impl fmt:: Display for InterpError < ' _ > {
540
537
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
541
- // Forward `Display` to `Debug`.
542
- fmt:: Debug :: fmt ( self , f)
538
+ use InterpError :: * ;
539
+ match * self {
540
+ Unsupported ( ref msg) => write ! ( f, "{}" , msg) ,
541
+ InvalidProgram ( ref msg) => write ! ( f, "{}" , msg) ,
542
+ UndefinedBehavior ( ref msg) => write ! ( f, "{}" , msg) ,
543
+ ResourceExhaustion ( ref msg) => write ! ( f, "{}" , msg) ,
544
+ MachineStop ( ref msg) => write ! ( f, "{}" , msg) ,
545
+ }
543
546
}
544
547
}
545
548
549
+ // Forward `Debug` to `Display`, so it does not look awful.
546
550
impl fmt:: Debug for InterpError < ' _ > {
547
551
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
548
- use InterpError :: * ;
549
- match * self {
550
- Unsupported ( ref msg) => write ! ( f, "{:?}" , msg) ,
551
- InvalidProgram ( ref msg) => write ! ( f, "{:?}" , msg) ,
552
- UndefinedBehavior ( ref msg) => write ! ( f, "{:?}" , msg) ,
553
- ResourceExhaustion ( ref msg) => write ! ( f, "{:?}" , msg) ,
554
- MachineStop ( ref msg) => write ! ( f, "{:?}" , msg) ,
555
- }
552
+ fmt:: Display :: fmt ( self , f)
556
553
}
557
554
}
558
555
0 commit comments