@@ -424,12 +424,13 @@ impl<'a> Parser<'a> {
424
424
/// returned, otherwise the character is consumed and the current position is
425
425
/// returned.
426
426
fn consume_pos ( & mut self , ch : char ) -> Option < ( Range < usize > , usize ) > {
427
- if let Some ( ( r, i, c) ) = self . peek ( ) {
428
- if ch == c {
429
- self . input_vec_index += 1 ;
430
- return Some ( ( r , i ) ) ;
431
- }
427
+ if let Some ( ( r, i, c) ) = self . peek ( )
428
+ && ch == c
429
+ {
430
+ self . input_vec_index += 1 ;
431
+ return Some ( ( r , i ) ) ;
432
432
}
433
+
433
434
None
434
435
}
435
436
@@ -549,30 +550,25 @@ impl<'a> Parser<'a> {
549
550
let word = self . word ( ) ;
550
551
551
552
// Recover from `r#ident` in format strings.
552
- // FIXME: use a let chain
553
- if word == "r" {
554
- if let Some ( ( r, _, '#' ) ) = self . peek ( ) {
555
- if self
556
- . peek_ahead ( )
557
- . is_some_and ( |( _, _, c) | rustc_lexer:: is_id_start ( c) )
558
- {
559
- self . input_vec_index += 1 ;
560
- let prefix_end = r. end ;
561
- let word = self . word ( ) ;
562
- let prefix_span = start..prefix_end;
563
- let full_span =
564
- start..self . input_vec_index2range ( self . input_vec_index ) . start ;
565
- self . errors . insert ( 0 , ParseError {
553
+ if word == "r"
554
+ && let Some ( ( r, _, '#' ) ) = self . peek ( )
555
+ && self . peek_ahead ( ) . is_some_and ( |( _, _, c) | rustc_lexer:: is_id_start ( c) )
556
+ {
557
+ self . input_vec_index += 1 ;
558
+ let prefix_end = r. end ;
559
+ let word = self . word ( ) ;
560
+ let prefix_span = start..prefix_end;
561
+ let full_span =
562
+ start..self . input_vec_index2range ( self . input_vec_index ) . start ;
563
+ self . errors . insert ( 0 , ParseError {
566
564
description : "raw identifiers are not supported" . to_owned ( ) ,
567
565
note : Some ( "identifiers in format strings can be keywords and don't need to be prefixed with `r#`" . to_string ( ) ) ,
568
566
label : "raw identifier used here" . to_owned ( ) ,
569
567
span : full_span,
570
568
secondary_label : None ,
571
569
suggestion : Suggestion :: RemoveRawIdent ( prefix_span) ,
572
570
} ) ;
573
- return Some ( ArgumentNamed ( word) ) ;
574
- }
575
- }
571
+ return Some ( ArgumentNamed ( word) ) ;
576
572
}
577
573
578
574
Some ( ArgumentNamed ( word) )
@@ -620,12 +616,10 @@ impl<'a> Parser<'a> {
620
616
}
621
617
622
618
// fill character
623
- if let Some ( ( r, _, c) ) = self . peek ( ) {
624
- if let Some ( ( _, _, '>' | '<' | '^' ) ) = self . peek_ahead ( ) {
625
- self . input_vec_index += 1 ;
626
- spec. fill = Some ( c) ;
627
- spec. fill_span = Some ( r) ;
628
- }
619
+ if let ( Some ( ( r, _, c) ) , Some ( ( _, _, '>' | '<' | '^' ) ) ) = ( self . peek ( ) , self . peek_ahead ( ) ) {
620
+ self . input_vec_index += 1 ;
621
+ spec. fill = Some ( c) ;
622
+ spec. fill_span = Some ( r) ;
629
623
}
630
624
// Alignment
631
625
if self . consume ( '<' ) {
@@ -703,24 +697,21 @@ impl<'a> Parser<'a> {
703
697
}
704
698
} else if let Some ( ( range, _) ) = self . consume_pos ( '?' ) {
705
699
spec. ty = "?" ;
706
- if let Some ( ( r, _, c) ) = self . peek ( ) {
707
- match c {
708
- '#' | 'x' | 'X' => self . errors . insert (
709
- 0 ,
710
- ParseError {
711
- description : format ! ( "expected `}}`, found `{c}`" ) ,
712
- note : None ,
713
- label : "expected `'}'`" . into ( ) ,
714
- span : r. clone ( ) ,
715
- secondary_label : None ,
716
- suggestion : Suggestion :: ReorderFormatParameter (
717
- range. start ..r. end ,
718
- format ! ( "{c}?" ) ,
719
- ) ,
720
- } ,
721
- ) ,
722
- _ => ( ) ,
723
- }
700
+ if let Some ( ( r, _, c @ ( '#' | 'x' | 'X' ) ) ) = self . peek ( ) {
701
+ self . errors . insert (
702
+ 0 ,
703
+ ParseError {
704
+ description : format ! ( "expected `}}`, found `{c}`" ) ,
705
+ note : None ,
706
+ label : "expected `'}'`" . into ( ) ,
707
+ span : r. clone ( ) ,
708
+ secondary_label : None ,
709
+ suggestion : Suggestion :: ReorderFormatParameter (
710
+ range. start ..r. end ,
711
+ format ! ( "{c}?" ) ,
712
+ ) ,
713
+ } ,
714
+ ) ;
724
715
}
725
716
} else {
726
717
spec. ty = self . word ( ) ;
0 commit comments