1
1
use std:: borrow:: Cow ;
2
+ use std:: fmt:: Write ;
2
3
3
4
use either:: Either ;
4
5
use rustc_errors:: codes:: * ;
@@ -15,7 +16,7 @@ use rustc_middle::mir::interpret::{
15
16
use rustc_middle:: ty:: { self , Mutability , Ty } ;
16
17
use rustc_span:: Span ;
17
18
use rustc_target:: abi:: call:: AdjustForForeignAbiError ;
18
- use rustc_target:: abi:: { Size , WrappingRange } ;
19
+ use rustc_target:: abi:: WrappingRange ;
19
20
20
21
use crate :: interpret:: InternKind ;
21
22
@@ -575,18 +576,21 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
575
576
. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
576
577
}
577
578
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 ( ) ) ;
589
592
diag. arg ( "ptr_offset_is_neg" , ptr_offset < 0 ) ;
593
+ diag. arg ( "ptr_offset_abs" , ptr_offset. unsigned_abs ( ) ) ;
590
594
diag. arg (
591
595
"alloc_size_minus_ptr_offset" ,
592
596
alloc_size. bytes ( ) . saturating_sub ( ptr_offset as u64 ) ,
@@ -600,7 +604,8 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
600
604
) ;
601
605
}
602
606
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 ( ) ) ;
604
609
diag. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
605
610
}
606
611
AlignmentCheckFailed ( Misalignment { required, has } , msg) => {
0 commit comments