@@ -611,6 +611,7 @@ impl<'a> Parser<'a> {
611
611
t if t. is_special_ident ( ) => "reserved identifier" ,
612
612
t if t. is_used_keyword ( ) => "keyword" ,
613
613
t if t. is_unused_keyword ( ) => "reserved keyword" ,
614
+ token:: DocComment ( ..) => "doc comment" ,
614
615
_ => return None ,
615
616
} )
616
617
}
@@ -644,8 +645,8 @@ impl<'a> Parser<'a> {
644
645
Ok ( ( ) )
645
646
} else {
646
647
let token_str = pprust:: token_to_string ( t) ;
647
- let this_token_str = self . this_token_to_string ( ) ;
648
- let mut err = self . fatal ( & format ! ( "expected `{}`, found `{}` " ,
648
+ let this_token_str = self . this_token_descr ( ) ;
649
+ let mut err = self . fatal ( & format ! ( "expected `{}`, found {} " ,
649
650
token_str,
650
651
this_token_str) ) ;
651
652
@@ -1444,17 +1445,17 @@ impl<'a> Parser<'a> {
1444
1445
Some ( body)
1445
1446
}
1446
1447
_ => {
1447
- let token_str = self . this_token_to_string ( ) ;
1448
- let mut err = self . fatal ( & format ! ( "expected `;` or `{{`, found `{}` " ,
1448
+ let token_str = self . this_token_descr ( ) ;
1449
+ let mut err = self . fatal ( & format ! ( "expected `;` or `{{`, found {} " ,
1449
1450
token_str) ) ;
1450
1451
err. span_label ( self . span , "expected `;` or `{`" ) ;
1451
1452
return Err ( err) ;
1452
1453
}
1453
1454
}
1454
1455
}
1455
1456
_ => {
1456
- let token_str = self . this_token_to_string ( ) ;
1457
- let mut err = self . fatal ( & format ! ( "expected `;` or `{{`, found `{}` " ,
1457
+ let token_str = self . this_token_descr ( ) ;
1458
+ let mut err = self . fatal ( & format ! ( "expected `;` or `{{`, found {} " ,
1458
1459
token_str) ) ;
1459
1460
err. span_label ( self . span , "expected `;` or `{`" ) ;
1460
1461
return Err ( err) ;
@@ -3917,8 +3918,8 @@ impl<'a> Parser<'a> {
3917
3918
etc_span = Some ( etc_sp) ;
3918
3919
break ;
3919
3920
}
3920
- let token_str = self . this_token_to_string ( ) ;
3921
- let mut err = self . fatal ( & format ! ( "expected `}}`, found `{}` " , token_str) ) ;
3921
+ let token_str = self . this_token_descr ( ) ;
3922
+ let mut err = self . fatal ( & format ! ( "expected `}}`, found {} " , token_str) ) ;
3922
3923
3923
3924
err. span_label ( self . span , "expected `}`" ) ;
3924
3925
let mut comma_sp = None ;
@@ -4680,8 +4681,8 @@ impl<'a> Parser<'a> {
4680
4681
} else {
4681
4682
""
4682
4683
} ;
4683
- let tok_str = self . this_token_to_string ( ) ;
4684
- let mut err = self . fatal ( & format ! ( "expected {}`(` or `{{`, found `{}` " ,
4684
+ let tok_str = self . this_token_descr ( ) ;
4685
+ let mut err = self . fatal ( & format ! ( "expected {}`(` or `{{`, found {} " ,
4685
4686
ident_str,
4686
4687
tok_str) ) ;
4687
4688
err. span_label ( self . span , format ! ( "expected {}`(` or `{{`" , ident_str) ) ;
@@ -4817,8 +4818,8 @@ impl<'a> Parser<'a> {
4817
4818
4818
4819
if !self . eat ( & token:: OpenDelim ( token:: Brace ) ) {
4819
4820
let sp = self . span ;
4820
- let tok = self . this_token_to_string ( ) ;
4821
- let mut e = self . span_fatal ( sp, & format ! ( "expected `{{`, found `{}` " , tok) ) ;
4821
+ let tok = self . this_token_descr ( ) ;
4822
+ let mut e = self . span_fatal ( sp, & format ! ( "expected `{{`, found {} " , tok) ) ;
4822
4823
let do_not_suggest_help =
4823
4824
self . token . is_keyword ( keywords:: In ) || self . token == token:: Colon ;
4824
4825
@@ -4880,6 +4881,7 @@ impl<'a> Parser<'a> {
4880
4881
}
4881
4882
_ => ( )
4882
4883
}
4884
+ e. span_label ( sp, "expected `{`" ) ;
4883
4885
return Err ( e) ;
4884
4886
}
4885
4887
@@ -4975,7 +4977,7 @@ impl<'a> Parser<'a> {
4975
4977
4976
4978
fn warn_missing_semicolon ( & self ) {
4977
4979
self . diagnostic ( ) . struct_span_warn ( self . span , {
4978
- & format ! ( "expected `;`, found `{}` " , self . this_token_to_string ( ) )
4980
+ & format ! ( "expected `;`, found {} " , self . this_token_descr ( ) )
4979
4981
} ) . note ( {
4980
4982
"This was erroneously allowed and will become a hard error in a future release"
4981
4983
} ) . emit ( ) ;
@@ -6014,9 +6016,9 @@ impl<'a> Parser<'a> {
6014
6016
self . expect ( & token:: Semi ) ?;
6015
6017
body
6016
6018
} else {
6017
- let token_str = self . this_token_to_string ( ) ;
6019
+ let token_str = self . this_token_descr ( ) ;
6018
6020
let mut err = self . fatal ( & format ! (
6019
- "expected `where`, `{{`, `(`, or `;` after struct name, found `{}` " ,
6021
+ "expected `where`, `{{`, `(`, or `;` after struct name, found {} " ,
6020
6022
token_str
6021
6023
) ) ;
6022
6024
err. span_label ( self . span , "expected `where`, `{`, `(`, or `;` after struct name" ) ;
@@ -6038,9 +6040,9 @@ impl<'a> Parser<'a> {
6038
6040
} else if self . token == token:: OpenDelim ( token:: Brace ) {
6039
6041
VariantData :: Struct ( self . parse_record_struct_body ( ) ?, ast:: DUMMY_NODE_ID )
6040
6042
} else {
6041
- let token_str = self . this_token_to_string ( ) ;
6043
+ let token_str = self . this_token_descr ( ) ;
6042
6044
let mut err = self . fatal ( & format ! (
6043
- "expected `where` or `{{` after union name, found `{}` " , token_str) ) ;
6045
+ "expected `where` or `{{` after union name, found {} " , token_str) ) ;
6044
6046
err. span_label ( self . span , "expected `where` or `{` after union name" ) ;
6045
6047
return Err ( err) ;
6046
6048
} ;
@@ -6088,9 +6090,9 @@ impl<'a> Parser<'a> {
6088
6090
}
6089
6091
self . eat ( & token:: CloseDelim ( token:: Brace ) ) ;
6090
6092
} else {
6091
- let token_str = self . this_token_to_string ( ) ;
6093
+ let token_str = self . this_token_descr ( ) ;
6092
6094
let mut err = self . fatal ( & format ! (
6093
- "expected `where`, or `{{` after struct name, found `{}` " , token_str) ) ;
6095
+ "expected `where`, or `{{` after struct name, found {} " , token_str) ) ;
6094
6096
err. span_label ( self . span , "expected `where`, or `{` after struct name" ) ;
6095
6097
return Err ( err) ;
6096
6098
}
@@ -6166,8 +6168,8 @@ impl<'a> Parser<'a> {
6166
6168
}
6167
6169
_ => {
6168
6170
let sp = self . sess . source_map ( ) . next_point ( self . prev_span ) ;
6169
- let mut err = self . struct_span_err ( sp, & format ! ( "expected `,`, or `}}`, found `{}` " ,
6170
- self . this_token_to_string ( ) ) ) ;
6171
+ let mut err = self . struct_span_err ( sp, & format ! ( "expected `,`, or `}}`, found {} " ,
6172
+ self . this_token_descr ( ) ) ) ;
6171
6173
if self . token . is_ident ( ) {
6172
6174
// This is likely another field; emit the diagnostic and keep going
6173
6175
err. span_suggestion_with_applicability (
@@ -6303,8 +6305,8 @@ impl<'a> Parser<'a> {
6303
6305
}
6304
6306
6305
6307
if !self . eat ( term) {
6306
- let token_str = self . this_token_to_string ( ) ;
6307
- let mut err = self . fatal ( & format ! ( "expected item, found `{}` " , token_str) ) ;
6308
+ let token_str = self . this_token_descr ( ) ;
6309
+ let mut err = self . fatal ( & format ! ( "expected item, found {} " , token_str) ) ;
6308
6310
if token_str == ";" {
6309
6311
let msg = "consider removing this semicolon" ;
6310
6312
err. span_suggestion_short_with_applicability (
0 commit comments