@@ -14,7 +14,7 @@ use rustc_hir as hir;
14
14
use rustc_macros:: HashStable ;
15
15
use rustc_session:: CtfeBacktrace ;
16
16
use rustc_span:: { Pos , Span , def_id:: DefId } ;
17
- use std:: { any:: Any , env , fmt} ;
17
+ use std:: { any:: Any , fmt} ;
18
18
19
19
#[ derive( Debug , Copy , Clone , PartialEq , Eq , HashStable , RustcEncodable , RustcDecodable ) ]
20
20
pub enum ErrorHandled {
@@ -326,7 +326,10 @@ pub enum UndefinedBehaviorInfo {
326
326
/// An enum discriminant was set to a value which was outside the range of valid values.
327
327
InvalidDiscriminant ( ScalarMaybeUndef ) ,
328
328
/// A slice/array index projection went out-of-bounds.
329
- BoundsCheckFailed { len : u64 , index : u64 } ,
329
+ BoundsCheckFailed {
330
+ len : u64 ,
331
+ index : u64 ,
332
+ } ,
330
333
/// Something was divided by 0 (x / 0).
331
334
DivisionByZero ,
332
335
/// Something was "remainded" by 0 (x % 0).
@@ -395,16 +398,14 @@ impl fmt::Debug for UndefinedBehaviorInfo {
395
398
"reading a null-terminated string starting at {:?} with no null found before end of allocation" ,
396
399
p,
397
400
) ,
398
- PointerUseAfterFree ( a) => write ! (
399
- f,
400
- "pointer to allocation {:?} was dereferenced after allocation got freed" ,
401
- a
402
- ) ,
401
+ PointerUseAfterFree ( a) => {
402
+ write ! ( f, "pointer to {:?} was dereferenced after this allocation got freed" , a)
403
+ }
403
404
InvalidNullPointerUsage => write ! ( f, "invalid use of NULL pointer" ) ,
404
405
PointerOutOfBounds { ptr, msg, allocation_size } => write ! (
405
406
f,
406
407
"{} failed: pointer must be in-bounds at offset {}, \
407
- but is outside bounds of allocation {} which has size {}",
408
+ but is outside bounds of {} which has size {}",
408
409
msg,
409
410
ptr. offset. bytes( ) ,
410
411
ptr. alloc_id,
@@ -416,16 +417,23 @@ impl fmt::Debug for UndefinedBehaviorInfo {
416
417
has. bytes( ) ,
417
418
required. bytes( )
418
419
) ,
419
- WriteToReadOnly ( a) => write ! ( f, "writing to read-only allocation {:?}" , a) ,
420
+ WriteToReadOnly ( a) => write ! ( f, "writing to {:?} which is read-only " , a) ,
420
421
InvalidFunctionPointer ( p) => {
421
422
write ! ( f, "using {:?} as function pointer but it does not point to a function" , p)
422
423
}
423
- DerefFunctionPointer ( a) => write ! ( f, "accessing data behind function pointer allocation {:?}" , a) ,
424
+ DerefFunctionPointer ( a) => write ! ( f, "accessing {:?} which contains a function " , a) ,
424
425
ValidationFailure ( ref err) => write ! ( f, "type validation failed: {}" , err) ,
425
426
InvalidBool ( b) => write ! ( f, "interpreting an invalid 8-bit value as a bool: {}" , b) ,
426
427
InvalidChar ( c) => write ! ( f, "interpreting an invalid 32-bit value as a char: {}" , c) ,
427
- InvalidUndefBytes ( Some ( p) ) => write ! ( f, "reading uninitialized memory at {:?}, but this operation requires initialized memory" , p) ,
428
- InvalidUndefBytes ( None ) => write ! ( f, "using uninitialized data, but this operation requires initialized memory" ) ,
428
+ InvalidUndefBytes ( Some ( p) ) => write ! (
429
+ f,
430
+ "reading uninitialized memory at {:?}, but this operation requires initialized memory" ,
431
+ p
432
+ ) ,
433
+ InvalidUndefBytes ( None ) => write ! (
434
+ f,
435
+ "using uninitialized data, but this operation requires initialized memory"
436
+ ) ,
429
437
DeadLocal => write ! ( f, "accessing a dead local variable" ) ,
430
438
ReadFromReturnPlace => write ! ( f, "tried to read from the return place" ) ,
431
439
}
@@ -472,21 +480,18 @@ impl fmt::Debug for UnsupportedOpInfo {
472
480
ConstPropUnsupported ( ref msg) => {
473
481
write ! ( f, "Constant propagation encountered an unsupported situation: {}" , msg)
474
482
}
475
- ReadForeignStatic ( did) => write ! ( f, "tried to read from foreign (extern) static {:?}" , did) ,
483
+ ReadForeignStatic ( did) => {
484
+ write ! ( f, "tried to read from foreign (extern) static {:?}" , did)
485
+ }
476
486
NoMirFor ( did) => write ! ( f, "could not load MIR for {:?}" , did) ,
477
487
ModifiedStatic => write ! (
478
488
f,
479
489
"tried to modify a static's initial value from another static's \
480
490
initializer"
481
491
) ,
482
492
483
- ReadPointerAsBytes => write ! (
484
- f,
485
- "unable to turn this pointer into raw bytes" ,
486
- ) ,
487
- ReadBytesAsPointer => {
488
- write ! ( f, "unable to turn these bytes into a pointer" )
489
- }
493
+ ReadPointerAsBytes => write ! ( f, "unable to turn this pointer into raw bytes" , ) ,
494
+ ReadBytesAsPointer => write ! ( f, "unable to turn these bytes into a pointer" ) ,
490
495
}
491
496
}
492
497
}
0 commit comments