@@ -254,19 +254,15 @@ impl<'a> Iterator for Parser<'a> {
254
254
// single open brace
255
255
self . last_open_brace = Some ( start..end) ;
256
256
let arg = self . argument ( ) ;
257
- if let Some ( close_brace_range) = self . consume_closing_brace ( & arg) {
257
+ self . ws ( ) ;
258
+ if let Some ( ( close_brace_range, _) ) = self . consume_pos ( '}' ) {
258
259
if self . is_source_literal {
259
260
self . arg_places . push ( start..close_brace_range. end ) ;
260
261
}
261
- } else if let Some ( ( _, _, c) ) = self . peek ( ) {
262
- match c {
263
- '?' => self . suggest_format_debug ( ) ,
264
- '<' | '^' | '>' => self . suggest_format_align ( c) ,
265
- _ => {
266
- self . suggest_positional_arg_instead_of_captured_arg ( arg. clone ( ) )
267
- }
268
- }
262
+ } else {
263
+ self . missing_closing_brace ( & arg) ;
269
264
}
265
+
270
266
Some ( Piece :: NextArgument ( Box :: new ( arg) ) )
271
267
}
272
268
}
@@ -437,17 +433,9 @@ impl<'a> Parser<'a> {
437
433
None
438
434
}
439
435
440
- /// Forces consumption of the specified character. If the character is not
441
- /// found, an error is emitted.
442
- fn consume_closing_brace ( & mut self , arg : & Argument < ' _ > ) -> Option < Range < usize > > {
443
- self . ws ( ) ;
444
-
436
+ /// Called if a closing brace was not found.
437
+ fn missing_closing_brace ( & mut self , arg : & Argument < ' _ > ) {
445
438
let ( range, description) = if let Some ( ( r, _, c) ) = self . peek ( ) {
446
- if c == '}' {
447
- self . input_vec_index += 1 ;
448
- return Some ( r) ;
449
- }
450
- // or r.clone()?
451
439
( r. start ..r. start , format ! ( "expected `}}`, found `{}`" , c. escape_debug( ) ) )
452
440
} else {
453
441
(
@@ -480,7 +468,13 @@ impl<'a> Parser<'a> {
480
468
suggestion : Suggestion :: None ,
481
469
} ) ;
482
470
483
- None
471
+ if let Some ( ( _, _, c) ) = self . peek ( ) {
472
+ match c {
473
+ '?' => self . suggest_format_debug ( ) ,
474
+ '<' | '^' | '>' => self . suggest_format_align ( c) ,
475
+ _ => self . suggest_positional_arg_instead_of_captured_arg ( arg) ,
476
+ }
477
+ }
484
478
}
485
479
486
480
/// Consumes all whitespace characters until the first non-whitespace character
@@ -905,7 +899,7 @@ impl<'a> Parser<'a> {
905
899
}
906
900
}
907
901
908
- fn suggest_positional_arg_instead_of_captured_arg ( & mut self , arg : Argument < ' a > ) {
902
+ fn suggest_positional_arg_instead_of_captured_arg ( & mut self , arg : & Argument < ' _ > ) {
909
903
// If the argument is not an identifier, it is not a field access.
910
904
if !arg. is_identifier ( ) {
911
905
return ;
0 commit comments