@@ -254,19 +254,15 @@ impl<'a> Iterator for Parser<'a> {
254254 // single open brace
255255 self . last_open_brace = Some ( start..end) ;
256256 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 ( '}' ) {
258259 if self . is_source_literal {
259260 self . arg_places . push ( start..close_brace_range. end ) ;
260261 }
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) ;
269264 }
265+
270266 Some ( Piece :: NextArgument ( Box :: new ( arg) ) )
271267 }
272268 }
@@ -437,17 +433,9 @@ impl<'a> Parser<'a> {
437433 None
438434 }
439435
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 < ' _ > ) {
445438 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()?
451439 ( r. start ..r. start , format ! ( "expected `}}`, found `{}`" , c. escape_debug( ) ) )
452440 } else {
453441 (
@@ -480,7 +468,13 @@ impl<'a> Parser<'a> {
480468 suggestion : Suggestion :: None ,
481469 } ) ;
482470
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+ }
484478 }
485479
486480 /// Consumes all whitespace characters until the first non-whitespace character
@@ -905,7 +899,7 @@ impl<'a> Parser<'a> {
905899 }
906900 }
907901
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 < ' _ > ) {
909903 // If the argument is not an identifier, it is not a field access.
910904 if !arg. is_identifier ( ) {
911905 return ;
0 commit comments