@@ -139,15 +139,15 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
139
139
_ => {
140
140
let expr = p. parse_expr ( ) ?;
141
141
if !args. named_args ( ) . is_empty ( ) {
142
- ecx. dcx ( ) . emit_err ( errors:: PositionalAfterNamed {
142
+ return Err ( ecx. dcx ( ) . create_err ( errors:: PositionalAfterNamed {
143
143
span : expr. span ,
144
144
args : args
145
145
. named_args ( )
146
146
. iter ( )
147
147
. filter_map ( |a| a. kind . ident ( ) . map ( |ident| ( a, ident) ) )
148
148
. map ( |( arg, n) | n. span . to ( arg. expr . span ) )
149
149
. collect ( ) ,
150
- } ) ;
150
+ } ) ) ;
151
151
}
152
152
args. add ( FormatArgument { kind : FormatArgumentKind :: Normal , expr } ) ;
153
153
}
@@ -313,6 +313,8 @@ fn make_format_args(
313
313
}
314
314
use ArgRef :: * ;
315
315
316
+ let mut unnamed_arg_after_named_arg = false ;
317
+
316
318
let mut lookup_arg = |arg : ArgRef < ' _ > ,
317
319
span : Option < Span > ,
318
320
used_as : PositionUsedAs ,
@@ -352,6 +354,7 @@ fn make_format_args(
352
354
// For the moment capturing variables from format strings expanded from macros is
353
355
// disabled (see RFC #2795)
354
356
ecx. dcx ( ) . emit_err ( errors:: FormatNoArgNamed { span, name } ) ;
357
+ unnamed_arg_after_named_arg = true ;
355
358
DummyResult :: raw_expr ( span, true )
356
359
} ;
357
360
Ok ( args. add ( FormatArgument { kind : FormatArgumentKind :: Captured ( ident) , expr } ) )
@@ -510,7 +513,8 @@ fn make_format_args(
510
513
} )
511
514
. collect :: < Vec < _ > > ( ) ;
512
515
513
- if !unused. is_empty ( ) {
516
+ let has_unused = !unused. is_empty ( ) ;
517
+ if has_unused {
514
518
// If there's a lot of unused arguments,
515
519
// let's check if this format arguments looks like another syntax (printf / shell).
516
520
let detect_foreign_fmt = unused. len ( ) > args. explicit_args ( ) . len ( ) / 2 ;
@@ -529,7 +533,7 @@ fn make_format_args(
529
533
530
534
// Only check for unused named argument names if there are no other errors to avoid causing
531
535
// 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 {
533
537
for & ( index, span, used_as) in & numeric_refences_to_named_arg {
534
538
let ( position_sp_to_replace, position_sp_for_msg) = match used_as {
535
539
Placeholder ( pspan) => ( span, pspan) ,
0 commit comments