@@ -139,15 +139,15 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
139139 _ => {
140140 let expr = p. parse_expr ( ) ?;
141141 if !args. named_args ( ) . is_empty ( ) {
142- ecx. dcx ( ) . emit_err ( errors:: PositionalAfterNamed {
142+ return Err ( ecx. dcx ( ) . create_err ( errors:: PositionalAfterNamed {
143143 span : expr. span ,
144144 args : args
145145 . named_args ( )
146146 . iter ( )
147147 . filter_map ( |a| a. kind . ident ( ) . map ( |ident| ( a, ident) ) )
148148 . map ( |( arg, n) | n. span . to ( arg. expr . span ) )
149149 . collect ( ) ,
150- } ) ;
150+ } ) ) ;
151151 }
152152 args. add ( FormatArgument { kind : FormatArgumentKind :: Normal , expr } ) ;
153153 }
@@ -313,6 +313,8 @@ fn make_format_args(
313313 }
314314 use ArgRef :: * ;
315315
316+ let mut unnamed_arg_after_named_arg = false ;
317+
316318 let mut lookup_arg = |arg : ArgRef < ' _ > ,
317319 span : Option < Span > ,
318320 used_as : PositionUsedAs ,
@@ -352,6 +354,7 @@ fn make_format_args(
352354 // For the moment capturing variables from format strings expanded from macros is
353355 // disabled (see RFC #2795)
354356 ecx. dcx ( ) . emit_err ( errors:: FormatNoArgNamed { span, name } ) ;
357+ unnamed_arg_after_named_arg = true ;
355358 DummyResult :: raw_expr ( span, true )
356359 } ;
357360 Ok ( args. add ( FormatArgument { kind : FormatArgumentKind :: Captured ( ident) , expr } ) )
@@ -510,7 +513,8 @@ fn make_format_args(
510513 } )
511514 . collect :: < Vec < _ > > ( ) ;
512515
513- if !unused. is_empty ( ) {
516+ let has_unused = !unused. is_empty ( ) ;
517+ if has_unused {
514518 // If there's a lot of unused arguments,
515519 // let's check if this format arguments looks like another syntax (printf / shell).
516520 let detect_foreign_fmt = unused. len ( ) > args. explicit_args ( ) . len ( ) / 2 ;
@@ -529,7 +533,7 @@ fn make_format_args(
529533
530534 // Only check for unused named argument names if there are no other errors to avoid causing
531535 // too much noise in output errors, such as when a named argument is entirely unused.
532- if invalid_refs. is_empty ( ) && ecx . dcx ( ) . has_errors ( ) . is_none ( ) {
536+ if invalid_refs. is_empty ( ) && !has_unused && !unnamed_arg_after_named_arg {
533537 for & ( index, span, used_as) in & numeric_refences_to_named_arg {
534538 let ( position_sp_to_replace, position_sp_for_msg) = match used_as {
535539 Placeholder ( pspan) => ( span, pspan) ,
0 commit comments