1
- use std:: fmt;
2
-
3
1
use rustc_errors:: {
4
2
DiagnosticArgValue , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler ,
5
3
IntoDiagnostic ,
@@ -427,24 +425,6 @@ pub struct UndefinedBehavior {
427
425
pub raw_bytes : RawBytesNote ,
428
426
}
429
427
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
-
448
428
pub trait ReportErrorExt {
449
429
/// Returns the diagnostic message for this error.
450
430
fn diagnostic_message ( & self ) -> DiagnosticMessage ;
@@ -454,11 +434,19 @@ pub trait ReportErrorExt {
454
434
builder : & mut DiagnosticBuilder < ' _ , G > ,
455
435
) ;
456
436
457
- fn debug ( self ) -> DebugExt < Self >
437
+ fn debug ( self ) -> String
458
438
where
459
439
Self : Sized ,
460
440
{
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
+ } )
462
450
}
463
451
}
464
452
@@ -481,7 +469,7 @@ impl<'a> ReportErrorExt for UndefinedBehaviorInfo<'a> {
481
469
use crate :: fluent_generated:: * ;
482
470
use UndefinedBehaviorInfo :: * ;
483
471
match self {
484
- Ub ( msg) => ( & * * msg) . into ( ) ,
472
+ Ub ( msg) => msg. clone ( ) . into ( ) ,
485
473
Unreachable => const_eval_unreachable,
486
474
BoundsCheckFailed { .. } => const_eval_bounds_check_failed,
487
475
DivisionByZero => const_eval_division_by_zero,
0 commit comments