@@ -18,7 +18,9 @@ use {rustc_attr_parsing as attr, rustc_hir as hir};
1818use super :: { ObligationCauseCode , PredicateObligation } ;
1919use crate :: error_reporting:: TypeErrCtxt ;
2020use crate :: error_reporting:: traits:: on_unimplemented_condition:: { Condition , ConditionOptions } ;
21- use crate :: error_reporting:: traits:: on_unimplemented_format:: { Ctx , FormatArgs , FormatString } ;
21+ use crate :: error_reporting:: traits:: on_unimplemented_format:: {
22+ Ctx , FormatArgs , FormatString , FormatWarning ,
23+ } ;
2224use crate :: errors:: {
2325 EmptyOnClauseInOnUnimplemented , InvalidOnClauseInOnUnimplemented , NoValueInOnUnimplemented ,
2426} ;
@@ -806,8 +808,38 @@ impl<'tcx> OnUnimplementedFormatString {
806808 // Warnings about format specifiers, deprecated parameters, wrong parameters etc.
807809 // In other words we'd like to let the author know, but we can still try to format the string later
808810 Ok ( FormatString { warnings, .. } ) => {
809- for w in warnings {
810- w. emit_warning ( tcx, trait_def_id)
811+ if self . is_diagnostic_namespace_variant {
812+ for w in warnings {
813+ w. emit_warning ( tcx, trait_def_id)
814+ }
815+ } else {
816+ for w in warnings {
817+ match w {
818+ FormatWarning :: UnknownParam { argument_name, span } => {
819+ let reported = struct_span_code_err ! (
820+ tcx. dcx( ) ,
821+ span,
822+ E0230 ,
823+ "cannot find parameter {} on this trait" ,
824+ argument_name,
825+ )
826+ . emit ( ) ;
827+ result = Err ( reported) ;
828+ }
829+ FormatWarning :: PositionalArgument { span, .. } => {
830+ let reported = struct_span_code_err ! (
831+ tcx. dcx( ) ,
832+ span,
833+ E0231 ,
834+ "positional format arguments are not allowed here"
835+ )
836+ . emit ( ) ;
837+ result = Err ( reported) ;
838+ }
839+ FormatWarning :: InvalidSpecifier { .. }
840+ | FormatWarning :: FutureIncompat { .. } => { }
841+ }
842+ }
811843 }
812844 }
813845 // Errors from the underlying `rustc_parse_format::Parser`
0 commit comments