11use std:: borrow:: Cow ;
2+ use std:: fmt:: Write ;
23
34use either:: Either ;
45use rustc_errors:: codes:: * ;
@@ -15,7 +16,7 @@ use rustc_middle::mir::interpret::{
1516use rustc_middle:: ty:: { self , Mutability , Ty } ;
1617use rustc_span:: Span ;
1718use rustc_target:: abi:: call:: AdjustForForeignAbiError ;
18- use rustc_target:: abi:: { Size , WrappingRange } ;
19+ use rustc_target:: abi:: WrappingRange ;
1920
2021use crate :: interpret:: InternKind ;
2122
@@ -575,18 +576,21 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
575576 . arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
576577 }
577578 PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
578- diag. arg ( "alloc_size" , alloc_size. bytes ( ) )
579- . arg ( "inbounds_size" , inbounds_size. bytes ( ) )
580- . arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
581- diag. arg (
582- "pointer" ,
583- Pointer :: new (
584- Some ( CtfeProvenance :: from ( alloc_id) ) ,
585- Size :: from_bytes ( ptr_offset as u64 ) ,
586- )
587- . to_string ( ) ,
588- ) ;
579+ diag. arg ( "alloc_size" , alloc_size. bytes ( ) ) ;
580+ diag. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
581+ diag. arg ( "pointer" , {
582+ let mut out = format ! ( "{:?}" , alloc_id) ;
583+ if ptr_offset > 0 {
584+ write ! ( out, "+{:#x}" , ptr_offset) . unwrap ( ) ;
585+ } else if ptr_offset < 0 {
586+ write ! ( out, "-{:#x}" , ptr_offset. unsigned_abs( ) ) . unwrap ( ) ;
587+ }
588+ out
589+ } ) ;
590+ diag. arg ( "inbounds_size_is_neg" , inbounds_size < 0 ) ;
591+ diag. arg ( "inbounds_size_abs" , inbounds_size. unsigned_abs ( ) ) ;
589592 diag. arg ( "ptr_offset_is_neg" , ptr_offset < 0 ) ;
593+ diag. arg ( "ptr_offset_abs" , ptr_offset. unsigned_abs ( ) ) ;
590594 diag. arg (
591595 "alloc_size_minus_ptr_offset" ,
592596 alloc_size. bytes ( ) . saturating_sub ( ptr_offset as u64 ) ,
@@ -600,7 +604,8 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
600604 ) ;
601605 }
602606
603- diag. arg ( "inbounds_size" , inbounds_size. bytes ( ) ) ;
607+ diag. arg ( "inbounds_size_is_neg" , inbounds_size < 0 ) ;
608+ diag. arg ( "inbounds_size_abs" , inbounds_size. unsigned_abs ( ) ) ;
604609 diag. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
605610 }
606611 AlignmentCheckFailed ( Misalignment { required, has } , msg) => {
0 commit comments