1- use std:: fmt;
2-
31use rustc_errors:: {
42 DiagnosticArgValue , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler ,
53 IntoDiagnostic ,
@@ -427,24 +425,6 @@ pub struct UndefinedBehavior {
427425 pub raw_bytes : RawBytesNote ,
428426}
429427
430- pub struct DebugExt < T > ( T ) ;
431-
432- impl < T : ReportErrorExt > fmt:: Debug for DebugExt < T > {
433- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
434- let s = ty:: tls:: with ( |tcx| {
435- let mut builder = tcx. sess . struct_allow ( "" ) ;
436- let handler = & tcx. sess . parse_sess . span_diagnostic ;
437- let message = self . 0 . diagnostic_message ( ) ;
438- self . 0 . add_args ( handler, & mut builder) ;
439- let s = handler. eagerly_translate_to_string ( message, builder. args ( ) ) ;
440- builder. cancel ( ) ;
441- s
442- } ) ;
443-
444- f. write_str ( & s)
445- }
446- }
447-
448428pub trait ReportErrorExt {
449429 /// Returns the diagnostic message for this error.
450430 fn diagnostic_message ( & self ) -> DiagnosticMessage ;
@@ -454,11 +434,19 @@ pub trait ReportErrorExt {
454434 builder : & mut DiagnosticBuilder < ' _ , G > ,
455435 ) ;
456436
457- fn debug ( self ) -> DebugExt < Self >
437+ fn debug ( self ) -> String
458438 where
459439 Self : Sized ,
460440 {
461- DebugExt ( self )
441+ ty:: tls:: with ( move |tcx| {
442+ let mut builder = tcx. sess . struct_allow ( DiagnosticMessage :: Str ( String :: new ( ) . into ( ) ) ) ;
443+ let handler = & tcx. sess . parse_sess . span_diagnostic ;
444+ let message = self . diagnostic_message ( ) ;
445+ self . add_args ( handler, & mut builder) ;
446+ let s = handler. eagerly_translate_to_string ( message, builder. args ( ) ) ;
447+ builder. cancel ( ) ;
448+ s
449+ } )
462450 }
463451}
464452
@@ -481,7 +469,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
481469 use crate :: fluent_generated:: * ;
482470 use UndefinedBehaviorInfo :: * ;
483471 match self {
484- Ub ( msg) => ( & * * msg) . into ( ) ,
472+ Ub ( msg) => msg. clone ( ) . into ( ) ,
485473 Unreachable => const_eval_unreachable,
486474 BoundsCheckFailed { .. } => const_eval_bounds_check_failed,
487475 DivisionByZero => const_eval_division_by_zero,
0 commit comments