@@ -1146,6 +1146,42 @@ impl<'a> Parser<'a> {
11461146 }
11471147 }
11481148
1149+ fn parse_field_name_maybe_tuple ( & mut self ) -> PResult < ' a , ThinVec < Ident > > {
1150+ let token:: Literal ( token:: Lit { kind : token:: Float , symbol, suffix } ) = self . token . kind
1151+ else {
1152+ return Ok ( thin_vec ! [ self . parse_field_name( ) ?] ) ;
1153+ } ;
1154+ Ok ( match self . break_up_float ( symbol) {
1155+ // 1e2
1156+ DestructuredFloat :: Single ( sym, sp) => {
1157+ self . bump ( ) ;
1158+ thin_vec ! [ Ident :: new( sym, sp) ]
1159+ }
1160+ // 1.
1161+ DestructuredFloat :: TrailingDot ( sym, sym_span, dot_span) => {
1162+ assert ! ( suffix. is_none( ) ) ;
1163+ // Analogous to `Self::break_and_eat`
1164+ self . token_cursor . break_last_token = true ;
1165+ // This might work, in cases like `1. 2`, and might not,
1166+ // in cases like `offset_of!(Ty, 1.)`. It depends on what comes
1167+ // after the float-like token, and therefore we have to make
1168+ // the other parts of the parser think that there is a dot literal.
1169+ self . token = Token :: new ( token:: Ident ( sym, false ) , sym_span) ;
1170+ self . bump_with ( ( Token :: new ( token:: Dot , dot_span) , self . token_spacing ) ) ;
1171+ thin_vec ! [ Ident :: new( sym, sym_span) ]
1172+ }
1173+ // 1.2 | 1.2e3
1174+ DestructuredFloat :: MiddleDot ( symbol1, ident1_span, _dot_span, symbol2, ident2_span) => {
1175+ self . bump ( ) ;
1176+ thin_vec ! [ Ident :: new( symbol1, ident1_span) , Ident :: new( symbol2, ident2_span) ]
1177+ }
1178+ DestructuredFloat :: Error => {
1179+ self . bump ( ) ;
1180+ thin_vec ! [ Ident :: new( symbol, self . prev_token. span) ]
1181+ }
1182+ } )
1183+ }
1184+
11491185 fn parse_expr_tuple_field_access (
11501186 & mut self ,
11511187 lo : Span ,
@@ -1852,49 +1888,7 @@ impl<'a> Parser<'a> {
18521888 let ( fields, _trailing, _recovered) = self . parse_seq_to_before_end (
18531889 & TokenKind :: CloseDelim ( Delimiter :: Parenthesis ) ,
18541890 seq_sep,
1855- |this| {
1856- let token:: Literal ( token:: Lit { kind : token:: Float , symbol, suffix } ) = this. token . kind
1857- else {
1858- return Ok ( thin_vec ! [ this. parse_field_name( ) ?] ) ;
1859- } ;
1860- let res = match this. break_up_float ( symbol) {
1861- // 1e2
1862- DestructuredFloat :: Single ( sym, sp) => {
1863- this. bump ( ) ;
1864- thin_vec ! [ Ident :: new( sym, sp) ]
1865- }
1866- // 1.
1867- DestructuredFloat :: TrailingDot ( sym, sym_span, dot_span) => {
1868- assert ! ( suffix. is_none( ) ) ;
1869- // Analogous to Self::break_and_eat
1870- this. token_cursor . break_last_token = true ;
1871- // This might work, in cases like `1. 2.3`, and might not,
1872- // in cases like `offset_of!(Ty, 1.)`.
1873- this. token = Token :: new ( token:: Ident ( sym, false ) , sym_span) ;
1874- this. bump_with ( ( Token :: new ( token:: Dot , dot_span) , this. token_spacing ) ) ;
1875- thin_vec ! [ Ident :: new( sym, sym_span) ]
1876- }
1877- // 1.2 | 1.2e3
1878- DestructuredFloat :: MiddleDot (
1879- symbol1,
1880- ident1_span,
1881- _dot_span,
1882- symbol2,
1883- ident2_span,
1884- ) => {
1885- this. bump ( ) ;
1886- thin_vec ! [
1887- Ident :: new( symbol1, ident1_span) ,
1888- Ident :: new( symbol2, ident2_span)
1889- ]
1890- }
1891- DestructuredFloat :: Error => {
1892- this. bump ( ) ;
1893- thin_vec ! [ Ident :: new( symbol, this. prev_token. span) ]
1894- }
1895- } ;
1896- Ok ( res)
1897- } ,
1891+ Parser :: parse_field_name_maybe_tuple,
18981892 ) ?;
18991893 let fields = fields. into_iter ( ) . flatten ( ) . collect :: < Vec < _ > > ( ) ;
19001894 let span = lo. to ( self . token . span ) ;
0 commit comments