@@ -18,6 +18,7 @@ use ty::TyCtxt;
1818use syntax:: symbol:: Symbol ;
1919use syntax:: ast:: { Attribute , MetaItem , MetaItemKind } ;
2020use syntax_pos:: { Span , DUMMY_SP } ;
21+ use hir:: { Item , ItemKind } ;
2122use hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
2223use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
2324use errors:: DiagnosticId ;
@@ -143,6 +144,26 @@ impl<'a, 'tcx> Visitor<'tcx> for LibFeatureCollector<'a, 'tcx> {
143144 NestedVisitorMap :: All ( & self . tcx . hir )
144145 }
145146
147+ fn visit_item ( & mut self , item : & ' tcx Item ) {
148+ match item. node {
149+ ItemKind :: ExternCrate ( _) => {
150+ let def_id = self . tcx . hir . local_def_id ( item. id ) ;
151+ let cnum = match self . tcx . extern_mod_stmt_cnum ( def_id) {
152+ Some ( cnum) => cnum,
153+ None => return ,
154+ } ;
155+
156+ for & ( feature, since) in self . tcx . defined_lib_features ( cnum) . iter ( ) {
157+ self . collect_feature ( feature, since, DUMMY_SP ) ;
158+ }
159+ }
160+
161+ _ => { }
162+ }
163+
164+ intravisit:: walk_item ( self , item) ;
165+ }
166+
146167 fn visit_attribute ( & mut self , attr : & ' tcx Attribute ) {
147168 if let Some ( ( feature, stable, span) ) = self . extract ( attr) {
148169 self . collect_feature ( feature, stable, span) ;
@@ -152,11 +173,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LibFeatureCollector<'a, 'tcx> {
152173
153174pub fn collect < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> LibFeatures {
154175 let mut collector = LibFeatureCollector :: new ( tcx) ;
155- for & cnum in tcx. crates ( ) . iter ( ) {
156- for & ( feature, since) in tcx. defined_lib_features ( cnum) . iter ( ) {
157- collector. collect_feature ( feature, since, DUMMY_SP ) ;
158- }
159- }
160176 intravisit:: walk_crate ( & mut collector, tcx. hir . krate ( ) ) ;
161177 collector. lib_features
162178}
0 commit comments