@@ -14,7 +14,7 @@ use rustc_hir as hir;
1414use rustc_macros:: HashStable ;
1515use rustc_session:: CtfeBacktrace ;
1616use rustc_span:: { Pos , Span , def_id:: DefId } ;
17- use std:: { any:: Any , env , fmt} ;
17+ use std:: { any:: Any , fmt} ;
1818
1919#[ derive( Debug , Copy , Clone , PartialEq , Eq , HashStable , RustcEncodable , RustcDecodable ) ]
2020pub enum ErrorHandled {
@@ -326,7 +326,10 @@ pub enum UndefinedBehaviorInfo {
326326 /// An enum discriminant was set to a value which was outside the range of valid values.
327327 InvalidDiscriminant ( ScalarMaybeUndef ) ,
328328 /// A slice/array index projection went out-of-bounds.
329- BoundsCheckFailed { len : u64 , index : u64 } ,
329+ BoundsCheckFailed {
330+ len : u64 ,
331+ index : u64 ,
332+ } ,
330333 /// Something was divided by 0 (x / 0).
331334 DivisionByZero ,
332335 /// Something was "remainded" by 0 (x % 0).
@@ -395,16 +398,14 @@ impl fmt::Debug for UndefinedBehaviorInfo {
395398 "reading a null-terminated string starting at {:?} with no null found before end of allocation" ,
396399 p,
397400 ) ,
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+ }
403404 InvalidNullPointerUsage => write ! ( f, "invalid use of NULL pointer" ) ,
404405 PointerOutOfBounds { ptr, msg, allocation_size } => write ! (
405406 f,
406407 "{} 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 {}",
408409 msg,
409410 ptr. offset. bytes( ) ,
410411 ptr. alloc_id,
@@ -416,16 +417,23 @@ impl fmt::Debug for UndefinedBehaviorInfo {
416417 has. bytes( ) ,
417418 required. bytes( )
418419 ) ,
419- WriteToReadOnly ( a) => write ! ( f, "writing to read-only allocation {:?}" , a) ,
420+ WriteToReadOnly ( a) => write ! ( f, "writing to {:?} which is read-only " , a) ,
420421 InvalidFunctionPointer ( p) => {
421422 write ! ( f, "using {:?} as function pointer but it does not point to a function" , p)
422423 }
423- DerefFunctionPointer ( a) => write ! ( f, "accessing data behind function pointer allocation {:?}" , a) ,
424+ DerefFunctionPointer ( a) => write ! ( f, "accessing {:?} which contains a function " , a) ,
424425 ValidationFailure ( ref err) => write ! ( f, "type validation failed: {}" , err) ,
425426 InvalidBool ( b) => write ! ( f, "interpreting an invalid 8-bit value as a bool: {}" , b) ,
426427 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+ ) ,
429437 DeadLocal => write ! ( f, "accessing a dead local variable" ) ,
430438 ReadFromReturnPlace => write ! ( f, "tried to read from the return place" ) ,
431439 }
@@ -472,21 +480,18 @@ impl fmt::Debug for UnsupportedOpInfo {
472480 ConstPropUnsupported ( ref msg) => {
473481 write ! ( f, "Constant propagation encountered an unsupported situation: {}" , msg)
474482 }
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+ }
476486 NoMirFor ( did) => write ! ( f, "could not load MIR for {:?}" , did) ,
477487 ModifiedStatic => write ! (
478488 f,
479489 "tried to modify a static's initial value from another static's \
480490 initializer"
481491 ) ,
482492
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" ) ,
490495 }
491496 }
492497}
0 commit comments