@@ -29,17 +29,16 @@ 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 } ;
3636
3737use proc_macro:: bridge:: client:: ProcMacro ;
38- use std:: io;
3938use std:: iter:: TrustedLen ;
40- use std:: mem;
4139use std:: num:: NonZeroUsize ;
4240use std:: path:: Path ;
41+ use std:: { io, iter, mem} ;
4342
4443pub ( super ) use cstore_impl:: provide;
4544pub use cstore_impl:: provide_extern;
@@ -984,64 +983,52 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
984983 DiagnosticItems { id_to_name, name_to_id }
985984 }
986985
986+ fn get_mod_child ( self , id : DefIndex , sess : & Session ) -> ModChild {
987+ let ident = self . item_ident ( id, sess) ;
988+ let kind = self . def_kind ( id) ;
989+ let def_id = self . local_def_id ( id) ;
990+ let res = Res :: Def ( kind, def_id) ;
991+ let vis = self . get_visibility ( id) ;
992+ let span = self . get_span ( id, sess) ;
993+ let macro_rules = match kind {
994+ DefKind :: Macro ( ..) => self . root . tables . macro_rules . get ( self , id) . is_some ( ) ,
995+ _ => false ,
996+ } ;
997+
998+ ModChild { ident, res, vis, span, macro_rules }
999+ }
1000+
9871001 /// Iterates over all named children of the given module,
9881002 /// including both proper items and reexports.
9891003 /// Module here is understood in name resolution sense - it can be a `mod` item,
9901004 /// or a crate root, or an enum, or a trait.
991- fn for_each_module_child (
1005+ fn get_module_children (
9921006 self ,
9931007 id : DefIndex ,
994- mut callback : impl FnMut ( ModChild ) ,
995- sess : & Session ,
996- ) {
997- if let Some ( data) = & self . root . proc_macro_data {
998- // If we are loading as a proc macro, we want to return
999- // the view of this crate as a proc macro crate.
1000- if id == CRATE_DEF_INDEX {
1001- for def_index in data. macros . decode ( self ) {
1002- let raw_macro = self . raw_proc_macro ( def_index) ;
1003- let res = Res :: Def (
1004- DefKind :: Macro ( macro_kind ( raw_macro) ) ,
1005- self . local_def_id ( def_index) ,
1006- ) ;
1007- let ident = self . item_ident ( def_index, sess) ;
1008- callback ( ModChild {
1009- ident,
1010- res,
1011- vis : ty:: Visibility :: Public ,
1012- span : ident. span ,
1013- macro_rules : false ,
1014- } ) ;
1008+ sess : & ' a Session ,
1009+ ) -> impl Iterator < Item = ModChild > + ' a {
1010+ iter:: from_generator ( move || {
1011+ if let Some ( data) = & self . root . proc_macro_data {
1012+ // If we are loading as a proc macro, we want to return
1013+ // the view of this crate as a proc macro crate.
1014+ if id == CRATE_DEF_INDEX {
1015+ for child_index in data. macros . decode ( self ) {
1016+ yield self . get_mod_child ( child_index, sess) ;
1017+ }
1018+ }
1019+ } else {
1020+ // Iterate over all children.
1021+ for child_index in self . root . tables . children . get ( self , id) . unwrap ( ) . decode ( self ) {
1022+ yield self . get_mod_child ( child_index, sess) ;
10151023 }
1016- }
1017- return ;
1018- }
10191024
1020- // Iterate over all children.
1021- if let Some ( children) = self . root . tables . children . get ( self , id) {
1022- for child_index in children. decode ( ( self , sess) ) {
1023- let ident = self . item_ident ( child_index, sess) ;
1024- let kind = self . def_kind ( child_index) ;
1025- let def_id = self . local_def_id ( child_index) ;
1026- let res = Res :: Def ( kind, def_id) ;
1027- let vis = self . get_visibility ( child_index) ;
1028- let span = self . get_span ( child_index, sess) ;
1029- let macro_rules = match kind {
1030- DefKind :: Macro ( ..) => {
1031- self . root . tables . macro_rules . get ( self , child_index) . is_some ( )
1025+ if let Some ( reexports) = self . root . tables . module_reexports . get ( self , id) {
1026+ for reexport in reexports. decode ( ( self , sess) ) {
1027+ yield reexport;
10321028 }
1033- _ => false ,
1034- } ;
1035-
1036- callback ( ModChild { ident, res, vis, span, macro_rules } ) ;
1037- }
1038- }
1039-
1040- if let Some ( exports) = self . root . tables . module_reexports . get ( self , id) {
1041- for exp in exports. decode ( ( self , sess) ) {
1042- callback ( exp) ;
1029+ }
10431030 }
1044- }
1031+ } )
10451032 }
10461033
10471034 fn is_ctfe_mir_available ( self , id : DefIndex ) -> bool {
@@ -1778,13 +1765,3 @@ impl CrateMetadata {
17781765 None
17791766 }
17801767}
1781-
1782- // Cannot be implemented on 'ProcMacro', as libproc_macro
1783- // does not depend on librustc_ast
1784- fn macro_kind ( raw : & ProcMacro ) -> MacroKind {
1785- match raw {
1786- ProcMacro :: CustomDerive { .. } => MacroKind :: Derive ,
1787- ProcMacro :: Attr { .. } => MacroKind :: Attr ,
1788- ProcMacro :: Bang { .. } => MacroKind :: Bang ,
1789- }
1790- }
0 commit comments