@@ -1119,9 +1119,8 @@ impl<'a> Parser<'a> {
1119
1119
if text. is_empty ( ) {
1120
1120
self . span_bug ( sp, "found empty literal suffix in Some" )
1121
1121
}
1122
- let msg = format ! ( "{} with a suffix is invalid" , kind) ;
1123
- self . struct_span_err ( sp, & msg)
1124
- . span_label ( sp, msg)
1122
+ self . struct_span_err ( sp, & format ! ( "suffixes on {} are invalid" , kind) )
1123
+ . span_label ( sp, format ! ( "invalid suffix `{}`" , text) )
1125
1124
. emit ( ) ;
1126
1125
}
1127
1126
}
@@ -2150,7 +2149,7 @@ impl<'a> Parser<'a> {
2150
2149
2151
2150
if suffix_illegal {
2152
2151
let sp = self . span ;
2153
- self . expect_no_suffix ( sp, lit. literal_name ( ) , suf)
2152
+ self . expect_no_suffix ( sp, & format ! ( "a {}" , lit. literal_name( ) ) , suf)
2154
2153
}
2155
2154
2156
2155
result. unwrap ( )
@@ -2481,7 +2480,8 @@ impl<'a> Parser<'a> {
2481
2480
}
2482
2481
2483
2482
fn parse_field_name ( & mut self ) -> PResult < ' a , Ident > {
2484
- if let token:: Literal ( token:: Integer ( name) , None ) = self . token {
2483
+ if let token:: Literal ( token:: Integer ( name) , suffix) = self . token {
2484
+ self . expect_no_suffix ( self . span , "a tuple index" , suffix) ;
2485
2485
self . bump ( ) ;
2486
2486
Ok ( Ident :: new ( name, self . prev_span ) )
2487
2487
} else {
@@ -3185,51 +3185,53 @@ impl<'a> Parser<'a> {
3185
3185
// expr.f
3186
3186
if self . eat ( & token:: Dot ) {
3187
3187
match self . token {
3188
- token:: Ident ( ..) => {
3189
- e = self . parse_dot_suffix ( e, lo) ?;
3190
- }
3191
- token:: Literal ( token:: Integer ( name) , _) => {
3192
- let span = self . span ;
3193
- self . bump ( ) ;
3194
- let field = ExprKind :: Field ( e, Ident :: new ( name, span) ) ;
3195
- e = self . mk_expr ( lo. to ( span) , field, ThinVec :: new ( ) ) ;
3196
- }
3197
- token:: Literal ( token:: Float ( n) , _suf) => {
3198
- self . bump ( ) ;
3199
- let fstr = n. as_str ( ) ;
3200
- let mut err = self . diagnostic ( )
3201
- . struct_span_err ( self . prev_span , & format ! ( "unexpected token: `{}`" , n) ) ;
3202
- err. span_label ( self . prev_span , "unexpected token" ) ;
3203
- if fstr. chars ( ) . all ( |x| "0123456789." . contains ( x) ) {
3204
- let float = match fstr. parse :: < f64 > ( ) . ok ( ) {
3205
- Some ( f) => f,
3206
- None => continue ,
3207
- } ;
3208
- let sugg = pprust:: to_string ( |s| {
3209
- use crate :: print:: pprust:: PrintState ;
3210
- s. popen ( ) ?;
3211
- s. print_expr ( & e) ?;
3212
- s. s . word ( "." ) ?;
3213
- s. print_usize ( float. trunc ( ) as usize ) ?;
3214
- s. pclose ( ) ?;
3215
- s. s . word ( "." ) ?;
3216
- s. s . word ( fstr. splitn ( 2 , "." ) . last ( ) . unwrap ( ) . to_string ( ) )
3217
- } ) ;
3218
- err. span_suggestion (
3219
- lo. to ( self . prev_span ) ,
3220
- "try parenthesizing the first index" ,
3221
- sugg,
3222
- Applicability :: MachineApplicable
3223
- ) ;
3188
+ token:: Ident ( ..) => {
3189
+ e = self . parse_dot_suffix ( e, lo) ?;
3224
3190
}
3225
- return Err ( err) ;
3191
+ token:: Literal ( token:: Integer ( name) , suffix) => {
3192
+ let span = self . span ;
3193
+ self . bump ( ) ;
3194
+ let field = ExprKind :: Field ( e, Ident :: new ( name, span) ) ;
3195
+ e = self . mk_expr ( lo. to ( span) , field, ThinVec :: new ( ) ) ;
3196
+
3197
+ self . expect_no_suffix ( span, "a tuple index" , suffix) ;
3198
+ }
3199
+ token:: Literal ( token:: Float ( n) , _suf) => {
3200
+ self . bump ( ) ;
3201
+ let fstr = n. as_str ( ) ;
3202
+ let mut err = self . diagnostic ( )
3203
+ . struct_span_err ( self . prev_span , & format ! ( "unexpected token: `{}`" , n) ) ;
3204
+ err. span_label ( self . prev_span , "unexpected token" ) ;
3205
+ if fstr. chars ( ) . all ( |x| "0123456789." . contains ( x) ) {
3206
+ let float = match fstr. parse :: < f64 > ( ) . ok ( ) {
3207
+ Some ( f) => f,
3208
+ None => continue ,
3209
+ } ;
3210
+ let sugg = pprust:: to_string ( |s| {
3211
+ use crate :: print:: pprust:: PrintState ;
3212
+ s. popen ( ) ?;
3213
+ s. print_expr ( & e) ?;
3214
+ s. s . word ( "." ) ?;
3215
+ s. print_usize ( float. trunc ( ) as usize ) ?;
3216
+ s. pclose ( ) ?;
3217
+ s. s . word ( "." ) ?;
3218
+ s. s . word ( fstr. splitn ( 2 , "." ) . last ( ) . unwrap ( ) . to_string ( ) )
3219
+ } ) ;
3220
+ err. span_suggestion (
3221
+ lo. to ( self . prev_span ) ,
3222
+ "try parenthesizing the first index" ,
3223
+ sugg,
3224
+ Applicability :: MachineApplicable
3225
+ ) ;
3226
+ }
3227
+ return Err ( err) ;
3226
3228
3227
- }
3228
- _ => {
3229
- // FIXME Could factor this out into non_fatal_unexpected or something.
3230
- let actual = self . this_token_to_string ( ) ;
3231
- self . span_err ( self . span , & format ! ( "unexpected token: `{}`" , actual) ) ;
3232
- }
3229
+ }
3230
+ _ => {
3231
+ // FIXME Could factor this out into non_fatal_unexpected or something.
3232
+ let actual = self . this_token_to_string ( ) ;
3233
+ self . span_err ( self . span , & format ! ( "unexpected token: `{}`" , actual) ) ;
3234
+ }
3233
3235
}
3234
3236
continue ;
3235
3237
}
@@ -7827,7 +7829,7 @@ impl<'a> Parser<'a> {
7827
7829
match self . token {
7828
7830
token:: Literal ( token:: Str_ ( s) , suf) | token:: Literal ( token:: StrRaw ( s, _) , suf) => {
7829
7831
let sp = self . span ;
7830
- self . expect_no_suffix ( sp, "ABI spec" , suf) ;
7832
+ self . expect_no_suffix ( sp, "an ABI spec" , suf) ;
7831
7833
self . bump ( ) ;
7832
7834
match abi:: lookup ( & s. as_str ( ) ) {
7833
7835
Some ( abi) => Ok ( Some ( abi) ) ,
@@ -8648,7 +8650,7 @@ impl<'a> Parser<'a> {
8648
8650
match self . parse_optional_str ( ) {
8649
8651
Some ( ( s, style, suf) ) => {
8650
8652
let sp = self . prev_span ;
8651
- self . expect_no_suffix ( sp, "string literal" , suf) ;
8653
+ self . expect_no_suffix ( sp, "a string literal" , suf) ;
8652
8654
Ok ( ( s, style) )
8653
8655
}
8654
8656
_ => {
0 commit comments