@@ -4,9 +4,10 @@ use std::fmt::Write;
44use either:: Either ;
55use rustc_abi:: WrappingRange ;
66use rustc_errors:: codes:: * ;
7+ use rustc_errors:: formatting:: DiagMessageAddArg ;
78use rustc_errors:: {
8- Diag , DiagArgValue , DiagMessage , Diagnostic , EmissionGuarantee , Level , MultiSpan ,
9- Subdiagnostic , msg,
9+ Diag , DiagArgMap , DiagArgValue , DiagMessage , Diagnostic , EmissionGuarantee , Level , MultiSpan ,
10+ Subdiagnostic , format_diag_message , msg,
1011} ;
1112use rustc_hir:: ConstContext ;
1213use rustc_macros:: { Diagnostic , Subdiagnostic } ;
@@ -359,14 +360,11 @@ pub struct FrameNote {
359360
360361impl Subdiagnostic for FrameNote {
361362 fn add_to_diag < G : EmissionGuarantee > ( self , diag : & mut Diag < ' _ , G > ) {
362- diag. arg ( "times" , self . times ) ;
363- diag. arg ( "where_" , self . where_ ) ;
364- diag. arg ( "instance" , self . instance ) ;
365363 let mut span: MultiSpan = self . span . into ( ) ;
366364 if self . has_label && !self . span . is_dummy ( ) {
367365 span. push_span_label ( self . span , msg ! ( "the failure occurred here" ) ) ;
368366 }
369- let msg = diag . eagerly_format ( msg ! (
367+ let msg = msg ! (
370368 r#"{$times ->
371369 [0] inside {$where_ ->
372370 [closure] closure
@@ -379,10 +377,11 @@ impl Subdiagnostic for FrameNote {
379377 *[other] {""}
380378 } ...]
381379 }"#
382- ) ) ;
383- diag. remove_arg ( "times" ) ;
384- diag. remove_arg ( "where_" ) ;
385- diag. remove_arg ( "instance" ) ;
380+ )
381+ . arg ( "times" , self . times )
382+ . arg ( "where_" , self . where_ )
383+ . arg ( "instance" , self . instance )
384+ . format ( ) ;
386385 diag. span_note ( span, msg) ;
387386 }
388387}
@@ -534,7 +533,7 @@ pub enum NonConstClosureNote {
534533 *[other] {""}
535534 }s"#
536535 ) ]
537- FnPtr ,
536+ FnPtr { kind : ConstContext } ,
538537 #[ note(
539538 r#"closures need an RFC before allowed to be called in {$kind ->
540539 [const] constant
@@ -543,7 +542,7 @@ pub enum NonConstClosureNote {
543542 *[other] {""}
544543 }s"#
545544 ) ]
546- Closure ,
545+ Closure { kind : ConstContext } ,
547546}
548547
549548#[ derive( Subdiagnostic ) ]
@@ -624,7 +623,7 @@ pub trait ReportErrorExt {
624623 let mut diag = dcx. struct_allow ( DiagMessage :: Str ( String :: new ( ) . into ( ) ) ) ;
625624 let message = self . diagnostic_message ( ) ;
626625 self . add_args ( & mut diag) ;
627- let s = dcx . eagerly_format_to_string ( message, diag. args . iter ( ) ) ;
626+ let s = format_diag_message ( & message, & diag. args ) . into_owned ( ) ;
628627 diag. cancel ( ) ;
629628 s
630629 } )
@@ -1086,12 +1085,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
10861085 }
10871086
10881087 let message = if let Some ( path) = self . path {
1089- err . dcx . eagerly_format_to_string (
1090- msg ! ( "constructing invalid value at {$path}" ) ,
1091- [ ( "path" . into ( ) , DiagArgValue :: Str ( path. into ( ) ) ) ] . iter ( ) . map ( | ( a , b ) | ( a , b ) ) ,
1088+ format_diag_message (
1089+ & msg ! ( "constructing invalid value at {$path}" ) ,
1090+ & DiagArgMap :: from_iter ( [ ( "path" . into ( ) , DiagArgValue :: Str ( path. into ( ) ) ) ] ) ,
10921091 )
10931092 } else {
1094- err . dcx . eagerly_format_to_string ( msg ! ( "constructing invalid value" ) , [ ] . into_iter ( ) )
1093+ Cow :: Borrowed ( "constructing invalid value" )
10951094 } ;
10961095
10971096 err. arg ( "front_matter" , message) ;
@@ -1117,12 +1116,13 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11171116 msg ! ( "in the range {$lo}..={$hi}" )
11181117 } ;
11191118
1120- let args = [
1121- ( "lo" . into ( ) , DiagArgValue :: Str ( lo. to_string ( ) . into ( ) ) ) ,
1122- ( "hi" . into ( ) , DiagArgValue :: Str ( hi. to_string ( ) . into ( ) ) ) ,
1123- ] ;
1124- let args = args. iter ( ) . map ( |( a, b) | ( a, b) ) ;
1125- let message = err. dcx . eagerly_format_to_string ( msg, args) ;
1119+ let message = format_diag_message (
1120+ & msg,
1121+ & DiagArgMap :: from_iter ( [
1122+ ( "lo" . into ( ) , DiagArgValue :: Str ( lo. to_string ( ) . into ( ) ) ) ,
1123+ ( "hi" . into ( ) , DiagArgValue :: Str ( hi. to_string ( ) . into ( ) ) ) ,
1124+ ] ) ,
1125+ ) ;
11261126 err. arg ( "in_range" , message) ;
11271127 }
11281128
@@ -1132,19 +1132,18 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11321132 }
11331133 PointerAsInt { expected } | Uninit { expected } => {
11341134 let msg = match expected {
1135- ExpectedKind :: Reference => msg ! ( "expected a reference" ) ,
1136- ExpectedKind :: Box => msg ! ( "expected a box" ) ,
1137- ExpectedKind :: RawPtr => msg ! ( "expected a raw pointer" ) ,
1138- ExpectedKind :: InitScalar => msg ! ( "expected initialized scalar value" ) ,
1139- ExpectedKind :: Bool => msg ! ( "expected a boolean" ) ,
1140- ExpectedKind :: Char => msg ! ( "expected a unicode scalar value" ) ,
1141- ExpectedKind :: Float => msg ! ( "expected a floating point number" ) ,
1142- ExpectedKind :: Int => msg ! ( "expected an integer" ) ,
1143- ExpectedKind :: FnPtr => msg ! ( "expected a function pointer" ) ,
1144- ExpectedKind :: EnumTag => msg ! ( "expected a valid enum tag" ) ,
1145- ExpectedKind :: Str => msg ! ( "expected a string" ) ,
1135+ ExpectedKind :: Reference => "expected a reference" ,
1136+ ExpectedKind :: Box => "expected a box" ,
1137+ ExpectedKind :: RawPtr => "expected a raw pointer" ,
1138+ ExpectedKind :: InitScalar => "expected initialized scalar value" ,
1139+ ExpectedKind :: Bool => "expected a boolean" ,
1140+ ExpectedKind :: Char => "expected a unicode scalar value" ,
1141+ ExpectedKind :: Float => "expected a floating point number" ,
1142+ ExpectedKind :: Int => "expected an integer" ,
1143+ ExpectedKind :: FnPtr => "expected a function pointer" ,
1144+ ExpectedKind :: EnumTag => "expected a valid enum tag" ,
1145+ ExpectedKind :: Str => "expected a string" ,
11461146 } ;
1147- let msg = err. dcx . eagerly_format_to_string ( msg, [ ] . into_iter ( ) ) ;
11481147 err. arg ( "expected" , msg) ;
11491148 }
11501149 InvalidEnumTag { value }
0 commit comments