@@ -740,7 +740,8 @@ impl<'a> Parser<'a> {
740
740
let lo = self . token . span ;
741
741
let vis = self . parse_visibility ( FollowedByType :: No ) ?;
742
742
let defaultness = self . parse_defaultness ( ) ;
743
- let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
743
+
744
+ let ( ident, kind, generics) = if self . eat_keyword ( kw:: Type ) {
744
745
self . parse_assoc_ty ( ) ?
745
746
} else if self . check_fn_front_matter ( ) {
746
747
let ( ident, sig, generics, body) = self . parse_fn ( at_end, & mut attrs, req_name) ?;
@@ -751,17 +752,9 @@ impl<'a> Parser<'a> {
751
752
self . parse_assoc_const ( ) ?
752
753
} ;
753
754
754
- Ok ( AssocItem {
755
- id : DUMMY_NODE_ID ,
756
- span : lo. to ( self . prev_span ) ,
757
- ident : name,
758
- attrs,
759
- vis,
760
- defaultness,
761
- generics,
762
- kind,
763
- tokens : None ,
764
- } )
755
+ let span = lo. to ( self . prev_span ) ;
756
+ let id = DUMMY_NODE_ID ;
757
+ Ok ( AssocItem { id, span, ident, attrs, vis, defaultness, generics, kind, tokens : None } )
765
758
}
766
759
767
760
/// This parses the grammar:
@@ -967,35 +960,25 @@ impl<'a> Parser<'a> {
967
960
Ok ( self . mk_item ( lo. to ( prev_span) , invalid, ItemKind :: ForeignMod ( m) , visibility, attrs) )
968
961
}
969
962
970
- /// Parses a foreign item.
963
+ /// Parses a foreign item (one in an `extern { ... }` block) .
971
964
pub fn parse_foreign_item ( & mut self ) -> PResult < ' a , P < ForeignItem > > {
972
965
maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
973
966
974
967
let mut attrs = self . parse_outer_attributes ( ) ?;
975
968
let lo = self . token . span ;
976
969
let vis = self . parse_visibility ( FollowedByType :: No ) ?;
977
970
978
- if self . check_keyword ( kw:: Type ) {
971
+ let ( ident , kind ) = if self . check_keyword ( kw:: Type ) {
979
972
// FOREIGN TYPE ITEM
980
- self . parse_item_foreign_type ( vis , lo , attrs )
973
+ self . parse_item_foreign_type ( ) ?
981
974
} else if self . check_fn_front_matter ( ) {
982
975
// FOREIGN FUNCTION ITEM
983
976
let ( ident, sig, generics, body) = self . parse_fn ( & mut false , & mut attrs, |_| true ) ?;
984
- let kind = ForeignItemKind :: Fn ( sig, generics, body) ;
985
- let span = lo. to ( self . prev_span ) ;
986
- Ok ( P ( ast:: ForeignItem {
987
- ident,
988
- attrs,
989
- kind,
990
- id : DUMMY_NODE_ID ,
991
- span,
992
- vis,
993
- tokens : None ,
994
- } ) )
977
+ ( ident, ForeignItemKind :: Fn ( sig, generics, body) )
995
978
} else if self . is_static_global ( ) {
996
979
// FOREIGN STATIC ITEM
997
980
self . bump ( ) ; // `static`
998
- self . parse_item_foreign_static ( vis , lo , attrs )
981
+ self . parse_item_foreign_static ( ) ?
999
982
} else if self . token . is_keyword ( kw:: Const ) {
1000
983
// Treat `const` as `static` for error recovery, but don't add it to expected tokens.
1001
984
self . bump ( ) ; // `const`
@@ -1007,66 +990,37 @@ impl<'a> Parser<'a> {
1007
990
Applicability :: MachineApplicable ,
1008
991
)
1009
992
. emit ( ) ;
1010
- self . parse_item_foreign_static ( vis , lo , attrs )
993
+ self . parse_item_foreign_static ( ) ?
1011
994
} else if let Some ( mac) = self . parse_assoc_macro_invoc ( "extern" , Some ( & vis) , & mut false ) ? {
1012
- let kind = ForeignItemKind :: Macro ( mac) ;
1013
- let span = lo. to ( self . prev_span ) ;
1014
- let ident = Ident :: invalid ( ) ;
1015
- Ok ( P ( ForeignItem { ident, span, id : DUMMY_NODE_ID , attrs, vis, kind, tokens : None } ) )
995
+ ( Ident :: invalid ( ) , ForeignItemKind :: Macro ( mac) )
1016
996
} else {
1017
997
if !attrs. is_empty ( ) {
1018
998
self . expected_item_err ( & attrs) ?;
1019
999
}
1020
- self . unexpected ( )
1021
- }
1000
+ self . unexpected ( ) ?
1001
+ } ;
1002
+
1003
+ let span = lo. to ( self . prev_span ) ;
1004
+ Ok ( P ( ast:: ForeignItem { ident, attrs, kind, id : DUMMY_NODE_ID , span, vis, tokens : None } ) )
1022
1005
}
1023
1006
1024
1007
/// Parses a static item from a foreign module.
1025
1008
/// Assumes that the `static` keyword is already parsed.
1026
- fn parse_item_foreign_static (
1027
- & mut self ,
1028
- vis : ast:: Visibility ,
1029
- lo : Span ,
1030
- attrs : Vec < Attribute > ,
1031
- ) -> PResult < ' a , P < ForeignItem > > {
1009
+ fn parse_item_foreign_static ( & mut self ) -> PResult < ' a , ( Ident , ForeignItemKind ) > {
1032
1010
let mutbl = self . parse_mutability ( ) ;
1033
1011
let ident = self . parse_ident ( ) ?;
1034
1012
self . expect ( & token:: Colon ) ?;
1035
1013
let ty = self . parse_ty ( ) ?;
1036
- let hi = self . token . span ;
1037
1014
self . expect_semi ( ) ?;
1038
- Ok ( P ( ForeignItem {
1039
- ident,
1040
- attrs,
1041
- kind : ForeignItemKind :: Static ( ty, mutbl) ,
1042
- id : DUMMY_NODE_ID ,
1043
- span : lo. to ( hi) ,
1044
- vis,
1045
- tokens : None ,
1046
- } ) )
1015
+ Ok ( ( ident, ForeignItemKind :: Static ( ty, mutbl) ) )
1047
1016
}
1048
1017
1049
1018
/// Parses a type from a foreign module.
1050
- fn parse_item_foreign_type (
1051
- & mut self ,
1052
- vis : ast:: Visibility ,
1053
- lo : Span ,
1054
- attrs : Vec < Attribute > ,
1055
- ) -> PResult < ' a , P < ForeignItem > > {
1019
+ fn parse_item_foreign_type ( & mut self ) -> PResult < ' a , ( Ident , ForeignItemKind ) > {
1056
1020
self . expect_keyword ( kw:: Type ) ?;
1057
-
1058
1021
let ident = self . parse_ident ( ) ?;
1059
- let hi = self . token . span ;
1060
1022
self . expect_semi ( ) ?;
1061
- Ok ( P ( ast:: ForeignItem {
1062
- ident,
1063
- attrs,
1064
- kind : ForeignItemKind :: Ty ,
1065
- id : DUMMY_NODE_ID ,
1066
- span : lo. to ( hi) ,
1067
- vis,
1068
- tokens : None ,
1069
- } ) )
1023
+ Ok ( ( ident, ForeignItemKind :: Ty ) )
1070
1024
}
1071
1025
1072
1026
fn is_static_global ( & mut self ) -> bool {
0 commit comments