@@ -18,6 +18,7 @@ use ty::TyCtxt;
18
18
use syntax:: symbol:: Symbol ;
19
19
use syntax:: ast:: { Attribute , MetaItem , MetaItemKind } ;
20
20
use syntax_pos:: { Span , DUMMY_SP } ;
21
+ use hir:: { Item , ItemKind } ;
21
22
use hir:: intravisit:: { self , NestedVisitorMap , Visitor } ;
22
23
use rustc_data_structures:: fx:: { FxHashSet , FxHashMap } ;
23
24
use errors:: DiagnosticId ;
@@ -143,6 +144,26 @@ impl<'a, 'tcx> Visitor<'tcx> for LibFeatureCollector<'a, 'tcx> {
143
144
NestedVisitorMap :: All ( & self . tcx . hir )
144
145
}
145
146
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
+
146
167
fn visit_attribute ( & mut self , attr : & ' tcx Attribute ) {
147
168
if let Some ( ( feature, stable, span) ) = self . extract ( attr) {
148
169
self . collect_feature ( feature, stable, span) ;
@@ -152,11 +173,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LibFeatureCollector<'a, 'tcx> {
152
173
153
174
pub fn collect < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> LibFeatures {
154
175
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
- }
160
176
intravisit:: walk_crate ( & mut collector, tcx. hir . krate ( ) ) ;
161
177
collector. lib_features
162
178
}
0 commit comments