1
+ use rustc_ast:: token:: Token ;
1
2
use rustc_ast:: Path ;
2
3
use rustc_errors:: { fluent, AddToDiagnostic , Applicability , EmissionGuarantee , IntoDiagnostic } ;
3
4
use rustc_macros:: { Diagnostic , Subdiagnostic } ;
4
5
use rustc_session:: errors:: ExprParenthesesNeeded ;
5
6
use rustc_span:: symbol:: Ident ;
6
7
use rustc_span:: { Span , Symbol } ;
7
8
8
- use crate :: parser:: { TokenDescription , TokenDescriptionKind } ;
9
+ use crate :: parser:: TokenDescription ;
9
10
10
11
#[ derive( Diagnostic ) ]
11
12
#[ diag( parser:: maybe_report_ambiguous_plus) ]
@@ -572,7 +573,7 @@ pub(crate) struct FoundExprWouldBeStmt {
572
573
#[ primary_span]
573
574
#[ label]
574
575
pub span : Span ,
575
- pub token : String ,
576
+ pub token : Token ,
576
577
#[ subdiagnostic]
577
578
pub suggestion : ExprParenthesesNeeded ,
578
579
}
@@ -871,7 +872,7 @@ pub(crate) struct SuffixedLiteralInAttribute {
871
872
pub ( crate ) struct InvalidMetaItem {
872
873
#[ primary_span]
873
874
pub span : Span ,
874
- pub token : String ,
875
+ pub token : Token ,
875
876
}
876
877
877
878
#[ derive( Subdiagnostic ) ]
@@ -908,22 +909,22 @@ pub(crate) enum ExpectedIdentifierFound {
908
909
}
909
910
910
911
impl ExpectedIdentifierFound {
911
- pub fn new ( token_descr_kind : Option < TokenDescriptionKind > , span : Span ) -> Self {
912
- ( match token_descr_kind {
913
- Some ( TokenDescriptionKind :: ReservedIdentifier ) => {
912
+ pub fn new ( token_descr : Option < TokenDescription > , span : Span ) -> Self {
913
+ ( match token_descr {
914
+ Some ( TokenDescription :: ReservedIdentifier ) => {
914
915
ExpectedIdentifierFound :: ReservedIdentifier
915
916
}
916
- Some ( TokenDescriptionKind :: Keyword ) => ExpectedIdentifierFound :: Keyword ,
917
- Some ( TokenDescriptionKind :: ReservedKeyword ) => ExpectedIdentifierFound :: ReservedKeyword ,
918
- Some ( TokenDescriptionKind :: DocComment ) => ExpectedIdentifierFound :: DocComment ,
917
+ Some ( TokenDescription :: Keyword ) => ExpectedIdentifierFound :: Keyword ,
918
+ Some ( TokenDescription :: ReservedKeyword ) => ExpectedIdentifierFound :: ReservedKeyword ,
919
+ Some ( TokenDescription :: DocComment ) => ExpectedIdentifierFound :: DocComment ,
919
920
None => ExpectedIdentifierFound :: Other ,
920
921
} ) ( span)
921
922
}
922
923
}
923
924
924
925
pub ( crate ) struct ExpectedIdentifier {
925
926
pub span : Span ,
926
- pub token_descr : TokenDescription ,
927
+ pub token : Token ,
927
928
pub suggest_raw : Option < SuggEscapeToUseAsIdentifier > ,
928
929
pub suggest_remove_comma : Option < SuggRemoveComma > ,
929
930
}
@@ -933,29 +934,31 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
933
934
self ,
934
935
handler : & ' a rustc_errors:: Handler ,
935
936
) -> rustc_errors:: DiagnosticBuilder < ' a , G > {
936
- let mut diag = handler. struct_diagnostic ( match self . token_descr . kind {
937
- Some ( TokenDescriptionKind :: ReservedIdentifier ) => {
937
+ let token_descr = super :: parser:: TokenDescription :: from_token ( & self . token ) ;
938
+
939
+ let mut diag = handler. struct_diagnostic ( match token_descr {
940
+ Some ( TokenDescription :: ReservedIdentifier ) => {
938
941
fluent:: parser:: expected_identifier_found_reserved_identifier_str
939
942
}
940
- Some ( TokenDescriptionKind :: Keyword ) => {
943
+ Some ( TokenDescription :: Keyword ) => {
941
944
fluent:: parser:: expected_identifier_found_keyword_str
942
945
}
943
- Some ( TokenDescriptionKind :: ReservedKeyword ) => {
946
+ Some ( TokenDescription :: ReservedKeyword ) => {
944
947
fluent:: parser:: expected_identifier_found_reserved_keyword_str
945
948
}
946
- Some ( TokenDescriptionKind :: DocComment ) => {
949
+ Some ( TokenDescription :: DocComment ) => {
947
950
fluent:: parser:: expected_identifier_found_doc_comment_str
948
951
}
949
952
None => fluent:: parser:: expected_identifier_found_str,
950
953
} ) ;
951
954
diag. set_span ( self . span ) ;
952
- diag. set_arg ( "token_str " , self . token_descr . name ) ;
955
+ diag. set_arg ( "token " , self . token ) ;
953
956
954
957
if let Some ( sugg) = self . suggest_raw {
955
958
sugg. add_to_diagnostic ( & mut diag) ;
956
959
}
957
960
958
- ExpectedIdentifierFound :: new ( self . token_descr . kind , self . span ) . add_to_diagnostic ( & mut diag) ;
961
+ ExpectedIdentifierFound :: new ( token_descr, self . span ) . add_to_diagnostic ( & mut diag) ;
959
962
960
963
if let Some ( sugg) = self . suggest_remove_comma {
961
964
sugg. add_to_diagnostic ( & mut diag) ;
@@ -967,7 +970,7 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedIdentifier {
967
970
968
971
pub ( crate ) struct ExpectedSemi {
969
972
pub span : Span ,
970
- pub token_descr : TokenDescription ,
973
+ pub token : Token ,
971
974
972
975
pub unexpected_token_label : Option < Span > ,
973
976
pub sugg : ExpectedSemiSugg ,
@@ -978,21 +981,23 @@ impl<'a, G: EmissionGuarantee> IntoDiagnostic<'a, G> for ExpectedSemi {
978
981
self ,
979
982
handler : & ' a rustc_errors:: Handler ,
980
983
) -> rustc_errors:: DiagnosticBuilder < ' a , G > {
981
- let mut diag = handler. struct_diagnostic ( match self . token_descr . kind {
982
- Some ( TokenDescriptionKind :: ReservedIdentifier ) => {
984
+ let token_descr = super :: parser:: TokenDescription :: from_token ( & self . token ) ;
985
+
986
+ let mut diag = handler. struct_diagnostic ( match token_descr {
987
+ Some ( TokenDescription :: ReservedIdentifier ) => {
983
988
fluent:: parser:: expected_semi_found_reserved_identifier_str
984
989
}
985
- Some ( TokenDescriptionKind :: Keyword ) => fluent:: parser:: expected_semi_found_keyword_str,
986
- Some ( TokenDescriptionKind :: ReservedKeyword ) => {
990
+ Some ( TokenDescription :: Keyword ) => fluent:: parser:: expected_semi_found_keyword_str,
991
+ Some ( TokenDescription :: ReservedKeyword ) => {
987
992
fluent:: parser:: expected_semi_found_reserved_keyword_str
988
993
}
989
- Some ( TokenDescriptionKind :: DocComment ) => {
994
+ Some ( TokenDescription :: DocComment ) => {
990
995
fluent:: parser:: expected_semi_found_doc_comment_str
991
996
}
992
997
None => fluent:: parser:: expected_semi_found_str,
993
998
} ) ;
994
999
diag. set_span ( self . span ) ;
995
- diag. set_arg ( "token_str " , self . token_descr . name ) ;
1000
+ diag. set_arg ( "token " , self . token ) ;
996
1001
997
1002
if let Some ( unexpected_token_label) = self . unexpected_token_label {
998
1003
diag. span_label ( unexpected_token_label, fluent:: parser:: label_unexpected_token) ;
0 commit comments