@@ -413,7 +413,7 @@ impl<'a, 'b> Context<'a, 'b> {
413413 /// Verifies one piece of a parse string, and remembers it if valid.
414414 /// All errors are not emitted as fatal so we can continue giving errors
415415 /// about this and possibly other format strings.
416- fn verify_piece ( & mut self , p : & parse:: Piece < ' _ > ) {
416+ fn verify_piece ( & mut self , p : & parse:: Piece < ' a > ) {
417417 match * p {
418418 parse:: String ( ..) => { }
419419 parse:: NextArgument ( ref arg) => {
@@ -433,6 +433,11 @@ impl<'a, 'b> Context<'a, 'b> {
433433 let has_precision = arg. format . precision != Count :: CountImplied ;
434434 let has_width = arg. format . width != Count :: CountImplied ;
435435
436+ if has_precision || has_width {
437+ // push before named params are resolved to aid diagnostics
438+ self . arg_with_formatting . push ( arg. format ) ;
439+ }
440+
436441 // argument second, if it's an implicit positional parameter
437442 // it's written second, so it should come after width/precision.
438443 let pos = match arg. position {
@@ -581,7 +586,11 @@ impl<'a, 'b> Context<'a, 'b> {
581586 let mut zero_based_note = false ;
582587
583588 let count = self . pieces . len ( )
584- + self . arg_with_formatting . iter ( ) . filter ( |fmt| fmt. precision_span . is_some ( ) ) . count ( ) ;
589+ + self
590+ . arg_with_formatting
591+ . iter ( )
592+ . filter ( |fmt| matches ! ( fmt. precision, parse:: CountIsParam ( _) ) )
593+ . count ( ) ;
585594 if self . names . is_empty ( ) && !numbered_position_args && count != self . num_args ( ) {
586595 e = self . ecx . struct_span_err (
587596 sp,
@@ -647,7 +656,7 @@ impl<'a, 'b> Context<'a, 'b> {
647656 + self
648657 . arg_with_formatting
649658 . iter ( )
650- . filter ( |fmt| fmt. precision_span . is_some ( ) )
659+ . filter ( |fmt| matches ! ( fmt. precision , parse :: CountIsParam ( _ ) ) )
651660 . count ( ) ;
652661 e. span_label (
653662 span,
@@ -899,26 +908,22 @@ impl<'a, 'b> Context<'a, 'b> {
899908 } ,
900909 position_span : arg. position_span ,
901910 format : parse:: FormatSpec {
902- fill : arg . format . fill ,
911+ fill : None ,
903912 align : parse:: AlignUnknown ,
904913 flags : 0 ,
905914 precision : parse:: CountImplied ,
906- precision_span : None ,
915+ precision_span : arg . format . precision_span ,
907916 width : parse:: CountImplied ,
908- width_span : None ,
917+ width_span : arg . format . width_span ,
909918 ty : arg. format . ty ,
910919 ty_span : arg. format . ty_span ,
911920 } ,
912921 } ;
913922
914923 let fill = arg. format . fill . unwrap_or ( ' ' ) ;
915-
916924 let pos_simple = arg. position . index ( ) == simple_arg. position . index ( ) ;
917925
918- if arg. format . precision_span . is_some ( ) || arg. format . width_span . is_some ( ) {
919- self . arg_with_formatting . push ( arg. format ) ;
920- }
921- if !pos_simple || arg. format != simple_arg. format || fill != ' ' {
926+ if !pos_simple || arg. format != simple_arg. format {
922927 self . all_pieces_simple = false ;
923928 }
924929
0 commit comments