@@ -29,17 +29,16 @@ 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 } ;
36
36
37
37
use proc_macro:: bridge:: client:: ProcMacro ;
38
- use std:: io;
39
38
use std:: iter:: TrustedLen ;
40
- use std:: mem;
41
39
use std:: num:: NonZeroUsize ;
42
40
use std:: path:: Path ;
41
+ use std:: { io, iter, mem} ;
43
42
44
43
pub ( super ) use cstore_impl:: provide;
45
44
pub use cstore_impl:: provide_extern;
@@ -984,64 +983,52 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
984
983
DiagnosticItems { id_to_name, name_to_id }
985
984
}
986
985
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
+
987
1001
/// Iterates over all named children of the given module,
988
1002
/// including both proper items and reexports.
989
1003
/// Module here is understood in name resolution sense - it can be a `mod` item,
990
1004
/// or a crate root, or an enum, or a trait.
991
- fn for_each_module_child (
1005
+ fn get_module_children (
992
1006
self ,
993
1007
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) ;
1015
1023
}
1016
- }
1017
- return ;
1018
- }
1019
1024
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;
1032
1028
}
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
+ }
1043
1030
}
1044
- }
1031
+ } )
1045
1032
}
1046
1033
1047
1034
fn is_ctfe_mir_available ( self , id : DefIndex ) -> bool {
@@ -1778,13 +1765,3 @@ impl CrateMetadata {
1778
1765
None
1779
1766
}
1780
1767
}
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