@@ -29,7 +29,7 @@ use rustc_session::cstore::{
29
29
CrateSource , ExternCrate , ForeignModule , LinkagePreference , NativeLib ,
30
30
} ;
31
31
use rustc_session:: Session ;
32
- use rustc_span:: hygiene:: { ExpnIndex , MacroKind } ;
32
+ use rustc_span:: hygiene:: ExpnIndex ;
33
33
use rustc_span:: source_map:: { respan, Spanned } ;
34
34
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
35
35
use rustc_span:: { self , BytePos , ExpnId , Pos , Span , SyntaxContext , DUMMY_SP } ;
@@ -989,6 +989,21 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
989
989
DiagnosticItems { id_to_name, name_to_id }
990
990
}
991
991
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
+
992
1007
/// Iterates over all named children of the given module,
993
1008
/// including both proper items and reexports.
994
1009
/// Module here is understood in name resolution sense - it can be a `mod` item,
@@ -1003,48 +1018,20 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
1003
1018
// If we are loading as a proc macro, we want to return
1004
1019
// the view of this crate as a proc macro crate.
1005
1020
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) ;
1020
1023
}
1021
1024
}
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) ;
1042
1029
}
1043
- }
1044
1030
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
+ }
1048
1035
}
1049
1036
}
1050
1037
} )
@@ -1784,13 +1771,3 @@ impl CrateMetadata {
1784
1771
None
1785
1772
}
1786
1773
}
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