@@ -740,7 +740,8 @@ impl<'a> Parser<'a> {
740740 let lo = self . token . span ;
741741 let vis = self . parse_visibility ( FollowedByType :: No ) ?;
742742 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 ) {
744745 self . parse_assoc_ty ( ) ?
745746 } else if self . check_fn_front_matter ( ) {
746747 let ( ident, sig, generics, body) = self . parse_fn ( at_end, & mut attrs, req_name) ?;
@@ -751,17 +752,9 @@ impl<'a> Parser<'a> {
751752 self . parse_assoc_const ( ) ?
752753 } ;
753754
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 } )
765758 }
766759
767760 /// This parses the grammar:
@@ -967,35 +960,25 @@ impl<'a> Parser<'a> {
967960 Ok ( self . mk_item ( lo. to ( prev_span) , invalid, ItemKind :: ForeignMod ( m) , visibility, attrs) )
968961 }
969962
970- /// Parses a foreign item.
963+ /// Parses a foreign item (one in an `extern { ... }` block) .
971964 pub fn parse_foreign_item ( & mut self ) -> PResult < ' a , P < ForeignItem > > {
972965 maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
973966
974967 let mut attrs = self . parse_outer_attributes ( ) ?;
975968 let lo = self . token . span ;
976969 let vis = self . parse_visibility ( FollowedByType :: No ) ?;
977970
978- if self . check_keyword ( kw:: Type ) {
971+ let ( ident , kind ) = if self . check_keyword ( kw:: Type ) {
979972 // FOREIGN TYPE ITEM
980- self . parse_item_foreign_type ( vis , lo , attrs )
973+ self . parse_item_foreign_type ( ) ?
981974 } else if self . check_fn_front_matter ( ) {
982975 // FOREIGN FUNCTION ITEM
983976 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) )
995978 } else if self . is_static_global ( ) {
996979 // FOREIGN STATIC ITEM
997980 self . bump ( ) ; // `static`
998- self . parse_item_foreign_static ( vis , lo , attrs )
981+ self . parse_item_foreign_static ( ) ?
999982 } else if self . token . is_keyword ( kw:: Const ) {
1000983 // Treat `const` as `static` for error recovery, but don't add it to expected tokens.
1001984 self . bump ( ) ; // `const`
@@ -1007,66 +990,37 @@ impl<'a> Parser<'a> {
1007990 Applicability :: MachineApplicable ,
1008991 )
1009992 . emit ( ) ;
1010- self . parse_item_foreign_static ( vis , lo , attrs )
993+ self . parse_item_foreign_static ( ) ?
1011994 } 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) )
1016996 } else {
1017997 if !attrs. is_empty ( ) {
1018998 self . expected_item_err ( & attrs) ?;
1019999 }
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 } ) )
10221005 }
10231006
10241007 /// Parses a static item from a foreign module.
10251008 /// 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 ) > {
10321010 let mutbl = self . parse_mutability ( ) ;
10331011 let ident = self . parse_ident ( ) ?;
10341012 self . expect ( & token:: Colon ) ?;
10351013 let ty = self . parse_ty ( ) ?;
1036- let hi = self . token . span ;
10371014 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) ) )
10471016 }
10481017
10491018 /// 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 ) > {
10561020 self . expect_keyword ( kw:: Type ) ?;
1057-
10581021 let ident = self . parse_ident ( ) ?;
1059- let hi = self . token . span ;
10601022 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 ) )
10701024 }
10711025
10721026 fn is_static_global ( & mut self ) -> bool {
0 commit comments