@@ -5,15 +5,14 @@ use either::Either;
55use rustc_abi:: WrappingRange ;
66use rustc_errors:: codes:: * ;
77use rustc_errors:: {
8- Diag , DiagArgValue , DiagCtxtHandle , DiagMessage , Diagnostic , EmissionGuarantee , Level ,
9- MultiSpan , Subdiagnostic ,
8+ Diag , DiagArgValue , DiagMessage , Diagnostic , EmissionGuarantee , Level , MultiSpan , Subdiagnostic ,
109} ;
1110use rustc_hir:: ConstContext ;
1211use rustc_macros:: { Diagnostic , LintDiagnostic , Subdiagnostic } ;
1312use rustc_middle:: mir:: interpret:: {
14- CheckInAllocMsg , CtfeProvenance , ExpectedKind , InterpErrorKind , InvalidMetaKind ,
15- InvalidProgramInfo , Misalignment , Pointer , PointerKind , ResourceExhaustionInfo ,
16- UndefinedBehaviorInfo , UnsupportedOpInfo , ValidationErrorInfo ,
13+ CtfeProvenance , ExpectedKind , InterpErrorKind , InvalidMetaKind , InvalidProgramInfo ,
14+ Misalignment , Pointer , PointerKind , ResourceExhaustionInfo , UndefinedBehaviorInfo ,
15+ UnsupportedOpInfo , ValidationErrorInfo ,
1716} ;
1817use rustc_middle:: ty:: { self , Mutability , Ty } ;
1918use rustc_span:: { Span , Symbol } ;
@@ -498,19 +497,6 @@ pub trait ReportErrorExt {
498497 }
499498}
500499
501- fn bad_pointer_message ( msg : CheckInAllocMsg , dcx : DiagCtxtHandle < ' _ > ) -> String {
502- use crate :: fluent_generated:: * ;
503-
504- let msg = match msg {
505- CheckInAllocMsg :: MemoryAccessTest => const_eval_memory_access_test,
506- CheckInAllocMsg :: PointerArithmeticTest => const_eval_pointer_arithmetic_test,
507- CheckInAllocMsg :: OffsetFromTest => const_eval_offset_from_test,
508- CheckInAllocMsg :: InboundsTest => const_eval_in_bounds_test,
509- } ;
510-
511- dcx. eagerly_translate_to_string ( msg, [ ] . into_iter ( ) )
512- }
513-
514500impl < ' a > ReportErrorExt for UndefinedBehaviorInfo < ' a > {
515501 fn diagnostic_message ( & self ) -> DiagMessage {
516502 use UndefinedBehaviorInfo :: * ;
@@ -564,7 +550,6 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
564550
565551 fn add_args < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) {
566552 use UndefinedBehaviorInfo :: * ;
567- let dcx = diag. dcx ;
568553 match self {
569554 Ub ( _) => { }
570555 Custom ( custom) => {
@@ -612,12 +597,10 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
612597 diag. arg ( "vtable_dyn_type" , vtable_dyn_type. to_string ( ) ) ;
613598 }
614599 PointerUseAfterFree ( alloc_id, msg) => {
615- diag. arg ( "alloc_id" , alloc_id)
616- . arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
600+ diag. arg ( "alloc_id" , alloc_id) . arg ( "operation" , format ! ( "{:?}" , msg) ) ;
617601 }
618602 PointerOutOfBounds { alloc_id, alloc_size, ptr_offset, inbounds_size, msg } => {
619603 diag. arg ( "alloc_size" , alloc_size. bytes ( ) ) ;
620- diag. arg ( "bad_pointer_message" , bad_pointer_message ( msg, dcx) ) ;
621604 diag. arg ( "pointer" , {
622605 let mut out = format ! ( "{:?}" , alloc_id) ;
623606 if ptr_offset > 0 {
@@ -627,14 +610,17 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
627610 }
628611 out
629612 } ) ;
613+ diag. arg ( "inbounds_size" , inbounds_size) ;
630614 diag. arg ( "inbounds_size_is_neg" , inbounds_size < 0 ) ;
631615 diag. arg ( "inbounds_size_abs" , inbounds_size. unsigned_abs ( ) ) ;
616+ diag. arg ( "ptr_offset" , ptr_offset) ;
632617 diag. arg ( "ptr_offset_is_neg" , ptr_offset < 0 ) ;
633618 diag. arg ( "ptr_offset_abs" , ptr_offset. unsigned_abs ( ) ) ;
634619 diag. arg (
635620 "alloc_size_minus_ptr_offset" ,
636621 alloc_size. bytes ( ) . saturating_sub ( ptr_offset as u64 ) ,
637622 ) ;
623+ diag. arg ( "operation" , format ! ( "{:?}" , msg) ) ;
638624 }
639625 DanglingIntPointer { addr, inbounds_size, msg } => {
640626 if addr != 0 {
@@ -644,9 +630,10 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
644630 ) ;
645631 }
646632
633+ diag. arg ( "inbounds_size" , inbounds_size) ;
647634 diag. arg ( "inbounds_size_is_neg" , inbounds_size < 0 ) ;
648635 diag. arg ( "inbounds_size_abs" , inbounds_size. unsigned_abs ( ) ) ;
649- diag. arg ( "bad_pointer_message " , bad_pointer_message ( msg , dcx ) ) ;
636+ diag. arg ( "operation " , format ! ( "{:?}" , msg ) ) ;
650637 }
651638 AlignmentCheckFailed ( Misalignment { required, has } , msg) => {
652639 diag. arg ( "required" , required. bytes ( ) ) ;
0 commit comments