@@ -335,16 +335,26 @@ pub trait HasFormatSpecifier: AstToken {
335
335
}
336
336
c if c == '_' || c. is_alphabetic ( ) => {
337
337
read_identifier ( & mut chars, & mut callback) ;
338
- if chars. peek ( ) . and_then ( |next| next. 1 . as_ref ( ) . ok ( ) ) . copied ( )
339
- != Some ( '$' )
340
- {
341
- continue ;
342
- }
343
- skip_char_and_emit (
344
- & mut chars,
345
- FormatSpecifier :: DollarSign ,
346
- & mut callback,
347
- ) ;
338
+ // can be either width (indicated by dollar sign, or type in which case
339
+ // the next sign has to be `}`)
340
+ let next =
341
+ chars. peek ( ) . and_then ( |next| next. 1 . as_ref ( ) . ok ( ) ) . copied ( ) ;
342
+ match next {
343
+ Some ( '$' ) => skip_char_and_emit (
344
+ & mut chars,
345
+ FormatSpecifier :: DollarSign ,
346
+ & mut callback,
347
+ ) ,
348
+ Some ( '}' ) => {
349
+ skip_char_and_emit (
350
+ & mut chars,
351
+ FormatSpecifier :: Close ,
352
+ & mut callback,
353
+ ) ;
354
+ continue ;
355
+ }
356
+ _ => continue ,
357
+ } ;
348
358
}
349
359
_ => { }
350
360
}
@@ -416,12 +426,11 @@ pub trait HasFormatSpecifier: AstToken {
416
426
}
417
427
}
418
428
419
- let mut cloned = chars. clone ( ) . take ( 2 ) ;
420
- let first = cloned . next ( ) . and_then ( |next| next . 1 . as_ref ( ) . ok ( ) ) . copied ( ) ;
421
- if first != Some ( '}' ) {
429
+ if let Some ( ( _ , Ok ( '}' ) ) ) = chars. peek ( ) {
430
+ skip_char_and_emit ( & mut chars , FormatSpecifier :: Close , & mut callback ) ;
431
+ } else {
422
432
continue ;
423
433
}
424
- skip_char_and_emit ( & mut chars, FormatSpecifier :: Close , & mut callback) ;
425
434
}
426
435
_ => {
427
436
while let Some ( ( _, Ok ( next_char) ) ) = chars. peek ( ) {
0 commit comments