@@ -49,7 +49,7 @@ enum DestructuredFloat {
49
49
/// 1.2 | 1.2e3
50
50
MiddleDot ( Symbol , Span , Span , Symbol , Span ) ,
51
51
/// Invalid
52
- Error ,
52
+ Error ( ErrorGuaranteed ) ,
53
53
}
54
54
55
55
impl < ' a > Parser < ' a > {
@@ -1008,7 +1008,7 @@ impl<'a> Parser<'a> {
1008
1008
self . mk_expr_tuple_field_access ( lo, ident1_span, base, sym1, None ) ;
1009
1009
self . mk_expr_tuple_field_access ( lo, ident2_span, base1, sym2, suffix)
1010
1010
}
1011
- DestructuredFloat :: Error => base,
1011
+ DestructuredFloat :: Error ( _ ) => base,
1012
1012
} )
1013
1013
}
1014
1014
_ => {
@@ -1018,7 +1018,7 @@ impl<'a> Parser<'a> {
1018
1018
}
1019
1019
}
1020
1020
1021
- fn error_unexpected_after_dot ( & self ) {
1021
+ fn error_unexpected_after_dot ( & self ) -> ErrorGuaranteed {
1022
1022
let actual = pprust:: token_to_string ( & self . token ) ;
1023
1023
let span = self . token . span ;
1024
1024
let sm = self . psess . source_map ( ) ;
@@ -1028,17 +1028,19 @@ impl<'a> Parser<'a> {
1028
1028
}
1029
1029
_ => ( span, actual) ,
1030
1030
} ;
1031
- self . dcx ( ) . emit_err ( errors:: UnexpectedTokenAfterDot { span, actual } ) ;
1031
+ self . dcx ( ) . emit_err ( errors:: UnexpectedTokenAfterDot { span, actual } )
1032
1032
}
1033
1033
1034
- // We need an identifier or integer, but the next token is a float.
1035
- // Break the float into components to extract the identifier or integer.
1034
+ /// We need an identifier or integer, but the next token is a float.
1035
+ /// Break the float into components to extract the identifier or integer.
1036
+ ///
1037
+ /// See also [`TokenKind::break_two_token_op`] which does similar splitting of `>>` into `>`.
1038
+ //
1036
1039
// FIXME: With current `TokenCursor` it's hard to break tokens into more than 2
1037
- // parts unless those parts are processed immediately. `TokenCursor` should either
1038
- // support pushing "future tokens" (would be also helpful to `break_and_eat`), or
1039
- // we should break everything including floats into more basic proc-macro style
1040
- // tokens in the lexer (probably preferable).
1041
- // See also `TokenKind::break_two_token_op` which does similar splitting of `>>` into `>`.
1040
+ // parts unless those parts are processed immediately. `TokenCursor` should either
1041
+ // support pushing "future tokens" (would be also helpful to `break_and_eat`), or
1042
+ // we should break everything including floats into more basic proc-macro style
1043
+ // tokens in the lexer (probably preferable).
1042
1044
fn break_up_float ( & self , float : Symbol , span : Span ) -> DestructuredFloat {
1043
1045
#[ derive( Debug ) ]
1044
1046
enum FloatComponent {
@@ -1078,34 +1080,30 @@ impl<'a> Parser<'a> {
1078
1080
DestructuredFloat :: Single ( Symbol :: intern ( i) , span)
1079
1081
}
1080
1082
// 1.
1081
- [ IdentLike ( i) , Punct ( '.' ) ] => {
1082
- let ( ident_span, dot_span) = if can_take_span_apart ( ) {
1083
- let ( span, ident_len) = ( span. data ( ) , BytePos :: from_usize ( i. len ( ) ) ) ;
1084
- let ident_span = span. with_hi ( span. lo + ident_len) ;
1085
- let dot_span = span. with_lo ( span. lo + ident_len) ;
1086
- ( ident_span, dot_span)
1083
+ [ IdentLike ( left) , Punct ( '.' ) ] => {
1084
+ let ( left_span, dot_span) = if can_take_span_apart ( ) {
1085
+ let left_span = span. with_hi ( span. lo ( ) + BytePos :: from_usize ( left. len ( ) ) ) ;
1086
+ let dot_span = span. with_lo ( left_span. hi ( ) ) ;
1087
+ ( left_span, dot_span)
1087
1088
} else {
1088
1089
( span, span)
1089
1090
} ;
1090
- let symbol = Symbol :: intern ( i ) ;
1091
- DestructuredFloat :: TrailingDot ( symbol , ident_span , dot_span)
1091
+ let left = Symbol :: intern ( left ) ;
1092
+ DestructuredFloat :: TrailingDot ( left , left_span , dot_span)
1092
1093
}
1093
1094
// 1.2 | 1.2e3
1094
- [ IdentLike ( i1) , Punct ( '.' ) , IdentLike ( i2) ] => {
1095
- let ( ident1_span, dot_span, ident2_span) = if can_take_span_apart ( ) {
1096
- let ( span, ident1_len) = ( span. data ( ) , BytePos :: from_usize ( i1. len ( ) ) ) ;
1097
- let ident1_span = span. with_hi ( span. lo + ident1_len) ;
1098
- let dot_span = span
1099
- . with_lo ( span. lo + ident1_len)
1100
- . with_hi ( span. lo + ident1_len + BytePos ( 1 ) ) ;
1101
- let ident2_span = self . token . span . with_lo ( span. lo + ident1_len + BytePos ( 1 ) ) ;
1102
- ( ident1_span, dot_span, ident2_span)
1095
+ [ IdentLike ( left) , Punct ( '.' ) , IdentLike ( right) ] => {
1096
+ let ( left_span, dot_span, right_span) = if can_take_span_apart ( ) {
1097
+ let left_span = span. with_hi ( span. lo ( ) + BytePos :: from_usize ( left. len ( ) ) ) ;
1098
+ let dot_span = span. with_lo ( left_span. hi ( ) ) . with_hi ( left_span. hi ( ) + BytePos ( 1 ) ) ;
1099
+ let right_span = span. with_lo ( dot_span. hi ( ) ) ;
1100
+ ( left_span, dot_span, right_span)
1103
1101
} else {
1104
1102
( span, span, span)
1105
1103
} ;
1106
- let symbol1 = Symbol :: intern ( i1 ) ;
1107
- let symbol2 = Symbol :: intern ( i2 ) ;
1108
- DestructuredFloat :: MiddleDot ( symbol1 , ident1_span , dot_span, symbol2 , ident2_span )
1104
+ let left = Symbol :: intern ( left ) ;
1105
+ let right = Symbol :: intern ( right ) ;
1106
+ DestructuredFloat :: MiddleDot ( left , left_span , dot_span, right , right_span )
1109
1107
}
1110
1108
// 1e+ | 1e- (recovered)
1111
1109
[ IdentLike ( _) , Punct ( '+' | '-' ) ] |
@@ -1116,8 +1114,8 @@ impl<'a> Parser<'a> {
1116
1114
// 1.2e+3 | 1.2e-3
1117
1115
[ IdentLike ( _) , Punct ( '.' ) , IdentLike ( _) , Punct ( '+' | '-' ) , IdentLike ( _) ] => {
1118
1116
// See the FIXME about `TokenCursor` above.
1119
- self . error_unexpected_after_dot ( ) ;
1120
- DestructuredFloat :: Error
1117
+ let guar = self . error_unexpected_after_dot ( ) ;
1118
+ DestructuredFloat :: Error ( guar )
1121
1119
}
1122
1120
_ => panic ! ( "unexpected components in a float token: {components:?}" ) ,
1123
1121
}
@@ -1183,7 +1181,7 @@ impl<'a> Parser<'a> {
1183
1181
fields. insert ( start_idx, Ident :: new ( symbol2, span2) ) ;
1184
1182
fields. insert ( start_idx, Ident :: new ( symbol1, span1) ) ;
1185
1183
}
1186
- DestructuredFloat :: Error => {
1184
+ DestructuredFloat :: Error ( _ ) => {
1187
1185
trailing_dot = None ;
1188
1186
fields. insert ( start_idx, Ident :: new ( symbol, self . prev_token . span ) ) ;
1189
1187
}
0 commit comments