@@ -79,6 +79,7 @@ pub struct LoweringContext<'a> {
79
79
trait_items : BTreeMap < hir:: TraitItemId , hir:: TraitItem > ,
80
80
impl_items : BTreeMap < hir:: ImplItemId , hir:: ImplItem > ,
81
81
bodies : BTreeMap < hir:: BodyId , hir:: Body > ,
82
+ exported_macros : Vec < hir:: MacroDef > ,
82
83
83
84
trait_impls : BTreeMap < DefId , Vec < NodeId > > ,
84
85
trait_default_impl : BTreeMap < DefId , NodeId > ,
@@ -123,6 +124,7 @@ pub fn lower_crate(sess: &Session,
123
124
trait_impls : BTreeMap :: new ( ) ,
124
125
trait_default_impl : BTreeMap :: new ( ) ,
125
126
catch_scopes : Vec :: new ( ) ,
127
+ exported_macros : Vec :: new ( ) ,
126
128
loop_scopes : Vec :: new ( ) ,
127
129
is_in_loop_condition : false ,
128
130
type_def_lifetime_params : DefIdMap ( ) ,
@@ -172,9 +174,10 @@ impl<'a> LoweringContext<'a> {
172
174
173
175
impl < ' lcx , ' interner > Visitor < ' lcx > for ItemLowerer < ' lcx , ' interner > {
174
176
fn visit_item ( & mut self , item : & ' lcx Item ) {
175
- let hir_item = self . lctx . lower_item ( item) ;
176
- self . lctx . items . insert ( item. id , hir_item) ;
177
- visit:: walk_item ( self , item) ;
177
+ if let Some ( hir_item) = self . lctx . lower_item ( item) {
178
+ self . lctx . items . insert ( item. id , hir_item) ;
179
+ visit:: walk_item ( self , item) ;
180
+ }
178
181
}
179
182
180
183
fn visit_trait_item ( & mut self , item : & ' lcx TraitItem ) {
@@ -197,14 +200,13 @@ impl<'a> LoweringContext<'a> {
197
200
198
201
let module = self . lower_mod ( & c. module ) ;
199
202
let attrs = self . lower_attrs ( & c. attrs ) ;
200
- let exported_macros = c. exported_macros . iter ( ) . map ( |m| self . lower_macro_def ( m) ) . collect ( ) ;
201
203
let body_ids = body_ids ( & self . bodies ) ;
202
204
203
205
hir:: Crate {
204
206
module : module,
205
207
attrs : attrs,
206
208
span : c. span ,
207
- exported_macros : exported_macros,
209
+ exported_macros : hir :: HirVec :: from ( self . exported_macros ) ,
208
210
items : self . items ,
209
211
trait_items : self . trait_items ,
210
212
impl_items : self . impl_items ,
@@ -1153,7 +1155,7 @@ impl<'a> LoweringContext<'a> {
1153
1155
bounds,
1154
1156
items)
1155
1157
}
1156
- ItemKind :: Mac ( _ ) => panic ! ( "Shouldn't still be around" ) ,
1158
+ ItemKind :: MacroDef ( .. ) | ItemKind :: Mac ( .. ) => panic ! ( "Shouldn't still be around" ) ,
1157
1159
}
1158
1160
}
1159
1161
@@ -1275,42 +1277,45 @@ impl<'a> LoweringContext<'a> {
1275
1277
}
1276
1278
}
1277
1279
1278
- fn lower_macro_def ( & mut self , m : & MacroDef ) -> hir:: MacroDef {
1279
- hir:: MacroDef {
1280
- name : m. ident . name ,
1281
- attrs : self . lower_attrs ( & m. attrs ) ,
1282
- id : m. id ,
1283
- span : m. span ,
1284
- body : m. body . clone ( ) . into ( ) ,
1285
- }
1286
- }
1287
-
1288
1280
fn lower_item_id ( & mut self , i : & Item ) -> SmallVector < hir:: ItemId > {
1289
- if let ItemKind :: Use ( ref view_path) = i. node {
1290
- if let ViewPathList ( _, ref imports) = view_path. node {
1291
- return iter:: once ( i. id ) . chain ( imports. iter ( ) . map ( |import| import. node . id ) )
1292
- . map ( |id| hir:: ItemId { id : id } ) . collect ( ) ;
1281
+ match i. node {
1282
+ ItemKind :: Use ( ref view_path) => {
1283
+ if let ViewPathList ( _, ref imports) = view_path. node {
1284
+ return iter:: once ( i. id ) . chain ( imports. iter ( ) . map ( |import| import. node . id ) )
1285
+ . map ( |id| hir:: ItemId { id : id } ) . collect ( ) ;
1286
+ }
1293
1287
}
1288
+ ItemKind :: MacroDef ( ..) => return SmallVector :: new ( ) ,
1289
+ _ => { }
1294
1290
}
1295
1291
SmallVector :: one ( hir:: ItemId { id : i. id } )
1296
1292
}
1297
1293
1298
- pub fn lower_item ( & mut self , i : & Item ) -> hir:: Item {
1294
+ pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
1299
1295
let mut name = i. ident . name ;
1300
1296
let attrs = self . lower_attrs ( & i. attrs ) ;
1301
1297
let mut vis = self . lower_visibility ( & i. vis ) ;
1298
+ if let ItemKind :: MacroDef ( ref tts) = i. node {
1299
+ if i. attrs . iter ( ) . any ( |attr| attr. name ( ) == "macro_export" ) {
1300
+ self . exported_macros . push ( hir:: MacroDef {
1301
+ name : name, attrs : attrs, id : i. id , span : i. span , body : tts. clone ( ) . into ( ) ,
1302
+ } ) ;
1303
+ }
1304
+ return None ;
1305
+ }
1306
+
1302
1307
let node = self . with_parent_def ( i. id , |this| {
1303
1308
this. lower_item_kind ( i. id , & mut name, & attrs, & mut vis, & i. node )
1304
1309
} ) ;
1305
1310
1306
- hir:: Item {
1311
+ Some ( hir:: Item {
1307
1312
id : i. id ,
1308
1313
name : name,
1309
1314
attrs : attrs,
1310
1315
node : node,
1311
1316
vis : vis,
1312
1317
span : i. span ,
1313
- }
1318
+ } )
1314
1319
}
1315
1320
1316
1321
fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem {
0 commit comments