@@ -18,7 +18,9 @@ use {rustc_attr_parsing as attr, rustc_hir as hir};
18
18
use super :: { ObligationCauseCode , PredicateObligation } ;
19
19
use crate :: error_reporting:: TypeErrCtxt ;
20
20
use 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
+ } ;
22
24
use crate :: errors:: {
23
25
EmptyOnClauseInOnUnimplemented , InvalidOnClauseInOnUnimplemented , NoValueInOnUnimplemented ,
24
26
} ;
@@ -806,8 +808,38 @@ impl<'tcx> OnUnimplementedFormatString {
806
808
// Warnings about format specifiers, deprecated parameters, wrong parameters etc.
807
809
// In other words we'd like to let the author know, but we can still try to format the string later
808
810
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
+ }
811
843
}
812
844
}
813
845
// Errors from the underlying `rustc_parse_format::Parser`
0 commit comments