@@ -6,8 +6,8 @@ use rustc_abi::WrappingRange;
66use rustc_errors:: codes:: * ;
77use rustc_errors:: formatting:: DiagMessageAddArg ;
88use rustc_errors:: {
9- Diag , DiagArgValue , DiagMessage , Diagnostic , EmissionGuarantee , Level , MultiSpan ,
10- Subdiagnostic , msg,
9+ Diag , DiagArgMap , DiagArgValue , DiagMessage , Diagnostic , EmissionGuarantee , Level , MultiSpan ,
10+ Subdiagnostic , format_diag_message , msg,
1111} ;
1212use rustc_hir:: ConstContext ;
1313use rustc_macros:: { Diagnostic , Subdiagnostic } ;
@@ -623,7 +623,7 @@ pub trait ReportErrorExt {
623623 let mut diag = dcx. struct_allow ( DiagMessage :: Str ( String :: new ( ) . into ( ) ) ) ;
624624 let message = self . diagnostic_message ( ) ;
625625 self . add_args ( & mut diag) ;
626- let s = dcx . eagerly_format_to_string ( message, diag. args . iter ( ) ) ;
626+ let s = format_diag_message ( & message, & diag. args ) . into_owned ( ) ;
627627 diag. cancel ( ) ;
628628 s
629629 } )
@@ -1085,12 +1085,12 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
10851085 }
10861086
10871087 let message = if let Some ( path) = self . path {
1088- err . dcx . eagerly_format_to_string (
1089- msg ! ( "constructing invalid value at {$path}" ) ,
1090- [ ( "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 ( ) ) ) ] ) ,
10911091 )
10921092 } else {
1093- err . dcx . eagerly_format_to_string ( msg ! ( "constructing invalid value" ) , [ ] . into_iter ( ) )
1093+ Cow :: Borrowed ( "constructing invalid value" )
10941094 } ;
10951095
10961096 err. arg ( "front_matter" , message) ;
@@ -1116,12 +1116,13 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11161116 msg ! ( "in the range {$lo}..={$hi}" )
11171117 } ;
11181118
1119- let args = [
1120- ( "lo" . into ( ) , DiagArgValue :: Str ( lo. to_string ( ) . into ( ) ) ) ,
1121- ( "hi" . into ( ) , DiagArgValue :: Str ( hi. to_string ( ) . into ( ) ) ) ,
1122- ] ;
1123- let args = args. iter ( ) . map ( |( a, b) | ( a, b) ) ;
1124- 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+ ) ;
11251126 err. arg ( "in_range" , message) ;
11261127 }
11271128
@@ -1131,19 +1132,18 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
11311132 }
11321133 PointerAsInt { expected } | Uninit { expected } => {
11331134 let msg = match expected {
1134- ExpectedKind :: Reference => msg ! ( "expected a reference" ) ,
1135- ExpectedKind :: Box => msg ! ( "expected a box" ) ,
1136- ExpectedKind :: RawPtr => msg ! ( "expected a raw pointer" ) ,
1137- ExpectedKind :: InitScalar => msg ! ( "expected initialized scalar value" ) ,
1138- ExpectedKind :: Bool => msg ! ( "expected a boolean" ) ,
1139- ExpectedKind :: Char => msg ! ( "expected a unicode scalar value" ) ,
1140- ExpectedKind :: Float => msg ! ( "expected a floating point number" ) ,
1141- ExpectedKind :: Int => msg ! ( "expected an integer" ) ,
1142- ExpectedKind :: FnPtr => msg ! ( "expected a function pointer" ) ,
1143- ExpectedKind :: EnumTag => msg ! ( "expected a valid enum tag" ) ,
1144- 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" ,
11451146 } ;
1146- let msg = err. dcx . eagerly_format_to_string ( msg, [ ] . into_iter ( ) ) ;
11471147 err. arg ( "expected" , msg) ;
11481148 }
11491149 InvalidEnumTag { value }
0 commit comments