@@ -1119,9 +1119,8 @@ impl<'a> Parser<'a> {
11191119 if text. is_empty ( ) {
11201120 self . span_bug ( sp, "found empty literal suffix in Some" )
11211121 }
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) )
11251124 . emit ( ) ;
11261125 }
11271126 }
@@ -2150,7 +2149,7 @@ impl<'a> Parser<'a> {
21502149
21512150 if suffix_illegal {
21522151 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)
21542153 }
21552154
21562155 result. unwrap ( )
@@ -2481,7 +2480,8 @@ impl<'a> Parser<'a> {
24812480 }
24822481
24832482 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) ;
24852485 self . bump ( ) ;
24862486 Ok ( Ident :: new ( name, self . prev_span ) )
24872487 } else {
@@ -3185,51 +3185,53 @@ impl<'a> Parser<'a> {
31853185 // expr.f
31863186 if self . eat ( & token:: Dot ) {
31873187 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) ?;
32243190 }
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) ;
32263228
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+ }
32333235 }
32343236 continue ;
32353237 }
@@ -7827,7 +7829,7 @@ impl<'a> Parser<'a> {
78277829 match self . token {
78287830 token:: Literal ( token:: Str_ ( s) , suf) | token:: Literal ( token:: StrRaw ( s, _) , suf) => {
78297831 let sp = self . span ;
7830- self . expect_no_suffix ( sp, "ABI spec" , suf) ;
7832+ self . expect_no_suffix ( sp, "an ABI spec" , suf) ;
78317833 self . bump ( ) ;
78327834 match abi:: lookup ( & s. as_str ( ) ) {
78337835 Some ( abi) => Ok ( Some ( abi) ) ,
@@ -8648,7 +8650,7 @@ impl<'a> Parser<'a> {
86488650 match self . parse_optional_str ( ) {
86498651 Some ( ( s, style, suf) ) => {
86508652 let sp = self . prev_span ;
8651- self . expect_no_suffix ( sp, "string literal" , suf) ;
8653+ self . expect_no_suffix ( sp, "a string literal" , suf) ;
86528654 Ok ( ( s, style) )
86538655 }
86548656 _ => {
0 commit comments