@@ -35,11 +35,10 @@ use 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;
@@ -994,60 +993,61 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
994993 /// including both proper items and reexports.
995994 /// Module here is understood in name resolution sense - it can be a `mod` item,
996995 /// or a crate root, or an enum, or a trait.
997- fn for_each_module_child (
996+ fn get_module_children (
998997 self ,
999998 id : DefIndex ,
1000- mut callback : impl FnMut ( ModChild ) ,
1001- sess : & Session ,
1002- ) {
1003- if let Some ( data) = & self . root . proc_macro_data {
1004- // If we are loading as a proc macro, we want to return
1005- // the view of this crate as a proc macro crate.
1006- if id == CRATE_DEF_INDEX {
1007- for def_index in data. macros . decode ( self ) {
1008- let raw_macro = self . raw_proc_macro ( def_index) ;
1009- let res = Res :: Def (
1010- DefKind :: Macro ( macro_kind ( raw_macro) ) ,
1011- self . local_def_id ( def_index) ,
1012- ) ;
1013- let ident = self . item_ident ( def_index, sess) ;
1014- callback ( ModChild {
1015- ident,
1016- res,
1017- vis : ty:: Visibility :: Public ,
1018- span : ident. span ,
1019- macro_rules : false ,
1020- } ) ;
999+ sess : & ' a Session ,
1000+ ) -> impl Iterator < Item = ModChild > + ' a {
1001+ iter:: from_generator ( move || {
1002+ if let Some ( data) = & self . root . proc_macro_data {
1003+ // If we are loading as a proc macro, we want to return
1004+ // the view of this crate as a proc macro crate.
1005+ 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+ } ;
1020+ }
10211021 }
1022+ return ;
10221023 }
1023- return ;
1024- }
10251024
1026- // Iterate over all children.
1027- if let Some ( children) = self . root . tables . children . get ( self , id) {
1028- for child_index in children. decode ( ( self , sess) ) {
1029- let ident = self . item_ident ( child_index, sess) ;
1030- let kind = self . def_kind ( child_index) ;
1031- let def_id = self . local_def_id ( child_index) ;
1032- let res = Res :: Def ( kind, def_id) ;
1033- let vis = self . get_visibility ( child_index) ;
1034- let span = self . get_span ( child_index, sess) ;
1035- let macro_rules = match kind {
1036- DefKind :: Macro ( ..) => {
1037- self . root . tables . macro_rules . get ( self , child_index) . is_some ( )
1038- }
1039- _ => false ,
1040- } ;
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+ } ;
10411040
1042- callback ( ModChild { ident, res, vis, span, macro_rules } ) ;
1041+ yield ModChild { ident, res, vis, span, macro_rules } ;
1042+ }
10431043 }
1044- }
10451044
1046- if let Some ( exports) = self . root . tables . module_reexports . get ( self , id) {
1047- for exp in exports. decode ( ( self , sess) ) {
1048- callback ( exp) ;
1045+ if let Some ( exports) = self . root . tables . module_reexports . get ( self , id) {
1046+ for exp in exports. decode ( ( self , sess) ) {
1047+ yield exp;
1048+ }
10491049 }
1050- }
1050+ } )
10511051 }
10521052
10531053 fn is_ctfe_mir_available ( self , id : DefIndex ) -> bool {
0 commit comments