@@ -29,7 +29,7 @@ use rustc_session::cstore::{
2929 CrateSource , ExternCrate , ForeignModule , LinkagePreference , NativeLib ,
3030} ;
3131use rustc_session:: Session ;
32- use rustc_span:: hygiene:: { ExpnIndex , MacroKind } ;
32+ use rustc_span:: hygiene:: ExpnIndex ;
3333use rustc_span:: source_map:: { respan, Spanned } ;
3434use rustc_span:: symbol:: { kw, Ident , Symbol } ;
3535use rustc_span:: { self , BytePos , ExpnId , Pos , Span , SyntaxContext , DUMMY_SP } ;
@@ -989,6 +989,21 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
989989 DiagnosticItems { id_to_name, name_to_id }
990990 }
991991
992+ fn get_mod_child ( self , id : DefIndex , sess : & Session ) -> ModChild {
993+ let ident = self . item_ident ( id, sess) ;
994+ let kind = self . def_kind ( id) ;
995+ let def_id = self . local_def_id ( id) ;
996+ let res = Res :: Def ( kind, def_id) ;
997+ let vis = self . get_visibility ( id) ;
998+ let span = self . get_span ( id, sess) ;
999+ let macro_rules = match kind {
1000+ DefKind :: Macro ( ..) => self . root . tables . macro_rules . get ( self , id) . is_some ( ) ,
1001+ _ => false ,
1002+ } ;
1003+
1004+ ModChild { ident, res, vis, span, macro_rules }
1005+ }
1006+
9921007 /// Iterates over all named children of the given module,
9931008 /// including both proper items and reexports.
9941009 /// Module here is understood in name resolution sense - it can be a `mod` item,
@@ -1003,48 +1018,20 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10031018 // If we are loading as a proc macro, we want to return
10041019 // the view of this crate as a proc macro crate.
10051020 if id == CRATE_DEF_INDEX {
1006- for def_index in data. macros . decode ( self ) {
1007- let raw_macro = self . raw_proc_macro ( def_index) ;
1008- let res = Res :: Def (
1009- DefKind :: Macro ( macro_kind ( raw_macro) ) ,
1010- self . local_def_id ( def_index) ,
1011- ) ;
1012- let ident = self . item_ident ( def_index, sess) ;
1013- yield ModChild {
1014- ident,
1015- res,
1016- vis : ty:: Visibility :: Public ,
1017- span : ident. span ,
1018- macro_rules : false ,
1019- } ;
1021+ for child_index in data. macros . decode ( self ) {
1022+ yield self . get_mod_child ( child_index, sess) ;
10201023 }
10211024 }
1022- return ;
1023- }
1024-
1025- // Iterate over all children.
1026- if let Some ( children) = self . root . tables . children . get ( self , id) {
1027- for child_index in children. decode ( ( self , sess) ) {
1028- let ident = self . item_ident ( child_index, sess) ;
1029- let kind = self . def_kind ( child_index) ;
1030- let def_id = self . local_def_id ( child_index) ;
1031- let res = Res :: Def ( kind, def_id) ;
1032- let vis = self . get_visibility ( child_index) ;
1033- let span = self . get_span ( child_index, sess) ;
1034- let macro_rules = match kind {
1035- DefKind :: Macro ( ..) => {
1036- self . root . tables . macro_rules . get ( self , child_index) . is_some ( )
1037- }
1038- _ => false ,
1039- } ;
1040-
1041- yield ModChild { ident, res, vis, span, macro_rules } ;
1025+ } else {
1026+ // Iterate over all children.
1027+ for child_index in self . root . tables . children . get ( self , id) . unwrap ( ) . decode ( self ) {
1028+ yield self . get_mod_child ( child_index, sess) ;
10421029 }
1043- }
10441030
1045- if let Some ( exports) = self . root . tables . module_reexports . get ( self , id) {
1046- for exp in exports. decode ( ( self , sess) ) {
1047- yield exp;
1031+ if let Some ( reexports) = self . root . tables . module_reexports . get ( self , id) {
1032+ for reexport in reexports. decode ( ( self , sess) ) {
1033+ yield reexport;
1034+ }
10481035 }
10491036 }
10501037 } )
@@ -1784,13 +1771,3 @@ impl CrateMetadata {
17841771 None
17851772 }
17861773}
1787-
1788- // Cannot be implemented on 'ProcMacro', as libproc_macro
1789- // does not depend on librustc_ast
1790- fn macro_kind ( raw : & ProcMacro ) -> MacroKind {
1791- match raw {
1792- ProcMacro :: CustomDerive { .. } => MacroKind :: Derive ,
1793- ProcMacro :: Attr { .. } => MacroKind :: Attr ,
1794- ProcMacro :: Bang { .. } => MacroKind :: Bang ,
1795- }
1796- }
0 commit comments