1
1
use std:: borrow:: Cow ;
2
+ use std:: fmt:: Write ;
2
3
3
4
use either:: Either ;
4
5
use rustc_errors:: {
@@ -14,7 +15,7 @@ use rustc_middle::mir::interpret::{
14
15
use rustc_middle:: ty:: { self , Mutability , Ty } ;
15
16
use rustc_span:: Span ;
16
17
use rustc_target:: abi:: call:: AdjustForForeignAbiError ;
17
- use rustc_target:: abi:: { Size , WrappingRange } ;
18
+ use rustc_target:: abi:: WrappingRange ;
18
19
19
20
use crate :: interpret:: InternKind ;
20
21
@@ -573,18 +574,21 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
573
574
. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
574
575
}
575
576
PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
576
- diag. arg ( "alloc_size" , alloc_size. bytes ( ) )
577
- . arg ( "inbounds_size" , inbounds_size. bytes ( ) )
578
- . arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
579
- diag. arg (
580
- "pointer" ,
581
- Pointer :: new (
582
- Some ( CtfeProvenance :: from ( alloc_id) ) ,
583
- Size :: from_bytes ( ptr_offset as u64 ) ,
584
- )
585
- . to_string ( ) ,
586
- ) ;
577
+ diag. arg ( "alloc_size" , alloc_size. bytes ( ) ) ;
578
+ diag. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
579
+ diag. arg ( "pointer" , {
580
+ let mut out = format ! ( "{:?}" , alloc_id) ;
581
+ if ptr_offset > 0 {
582
+ write ! ( out, "+{:#x}" , ptr_offset) . unwrap ( ) ;
583
+ } else if ptr_offset < 0 {
584
+ write ! ( out, "-{:#x}" , ptr_offset. unsigned_abs( ) ) . unwrap ( ) ;
585
+ }
586
+ out
587
+ } ) ;
588
+ diag. arg ( "inbounds_size_is_neg" , inbounds_size < 0 ) ;
589
+ diag. arg ( "inbounds_size_abs" , inbounds_size. unsigned_abs ( ) ) ;
587
590
diag. arg ( "ptr_offset_is_neg" , ptr_offset < 0 ) ;
591
+ diag. arg ( "ptr_offset_abs" , ptr_offset. unsigned_abs ( ) ) ;
588
592
diag. arg (
589
593
"alloc_size_minus_ptr_offset" ,
590
594
alloc_size. bytes ( ) . saturating_sub ( ptr_offset as u64 ) ,
@@ -598,7 +602,8 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
598
602
) ;
599
603
}
600
604
601
- diag. arg ( "inbounds_size" , inbounds_size. bytes ( ) ) ;
605
+ diag. arg ( "inbounds_size_is_neg" , inbounds_size < 0 ) ;
606
+ diag. arg ( "inbounds_size_abs" , inbounds_size. unsigned_abs ( ) ) ;
602
607
diag. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
603
608
}
604
609
AlignmentCheckFailed ( Misalignment { required, has } , msg) => {
0 commit comments