@@ -413,7 +413,7 @@ impl<'a, 'b> Context<'a, 'b> {
413
413
/// Verifies one piece of a parse string, and remembers it if valid.
414
414
/// All errors are not emitted as fatal so we can continue giving errors
415
415
/// 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 > ) {
417
417
match * p {
418
418
parse:: String ( ..) => { }
419
419
parse:: NextArgument ( ref arg) => {
@@ -433,6 +433,11 @@ impl<'a, 'b> Context<'a, 'b> {
433
433
let has_precision = arg. format . precision != Count :: CountImplied ;
434
434
let has_width = arg. format . width != Count :: CountImplied ;
435
435
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
+
436
441
// argument second, if it's an implicit positional parameter
437
442
// it's written second, so it should come after width/precision.
438
443
let pos = match arg. position {
@@ -581,7 +586,11 @@ impl<'a, 'b> Context<'a, 'b> {
581
586
let mut zero_based_note = false ;
582
587
583
588
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 ( ) ;
585
594
if self . names . is_empty ( ) && !numbered_position_args && count != self . num_args ( ) {
586
595
e = self . ecx . struct_span_err (
587
596
sp,
@@ -647,7 +656,7 @@ impl<'a, 'b> Context<'a, 'b> {
647
656
+ self
648
657
. arg_with_formatting
649
658
. iter ( )
650
- . filter ( |fmt| fmt. precision_span . is_some ( ) )
659
+ . filter ( |fmt| matches ! ( fmt. precision , parse :: CountIsParam ( _ ) ) )
651
660
. count ( ) ;
652
661
e. span_label (
653
662
span,
@@ -899,26 +908,22 @@ impl<'a, 'b> Context<'a, 'b> {
899
908
} ,
900
909
position_span : arg. position_span ,
901
910
format : parse:: FormatSpec {
902
- fill : arg . format . fill ,
911
+ fill : None ,
903
912
align : parse:: AlignUnknown ,
904
913
flags : 0 ,
905
914
precision : parse:: CountImplied ,
906
- precision_span : None ,
915
+ precision_span : arg . format . precision_span ,
907
916
width : parse:: CountImplied ,
908
- width_span : None ,
917
+ width_span : arg . format . width_span ,
909
918
ty : arg. format . ty ,
910
919
ty_span : arg. format . ty_span ,
911
920
} ,
912
921
} ;
913
922
914
923
let fill = arg. format . fill . unwrap_or ( ' ' ) ;
915
-
916
924
let pos_simple = arg. position . index ( ) == simple_arg. position . index ( ) ;
917
925
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 {
922
927
self . all_pieces_simple = false ;
923
928
}
924
929
0 commit comments