@@ -79,6 +79,7 @@ pub struct LoweringContext<'a> {
7979 trait_items : BTreeMap < hir:: TraitItemId , hir:: TraitItem > ,
8080 impl_items : BTreeMap < hir:: ImplItemId , hir:: ImplItem > ,
8181 bodies : BTreeMap < hir:: BodyId , hir:: Body > ,
82+ exported_macros : Vec < hir:: MacroDef > ,
8283
8384 trait_impls : BTreeMap < DefId , Vec < NodeId > > ,
8485 trait_default_impl : BTreeMap < DefId , NodeId > ,
@@ -123,6 +124,7 @@ pub fn lower_crate(sess: &Session,
123124 trait_impls : BTreeMap :: new ( ) ,
124125 trait_default_impl : BTreeMap :: new ( ) ,
125126 catch_scopes : Vec :: new ( ) ,
127+ exported_macros : Vec :: new ( ) ,
126128 loop_scopes : Vec :: new ( ) ,
127129 is_in_loop_condition : false ,
128130 type_def_lifetime_params : DefIdMap ( ) ,
@@ -172,9 +174,10 @@ impl<'a> LoweringContext<'a> {
172174
173175 impl < ' lcx , ' interner > Visitor < ' lcx > for ItemLowerer < ' lcx , ' interner > {
174176 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+ }
178181 }
179182
180183 fn visit_trait_item ( & mut self , item : & ' lcx TraitItem ) {
@@ -197,14 +200,13 @@ impl<'a> LoweringContext<'a> {
197200
198201 let module = self . lower_mod ( & c. module ) ;
199202 let attrs = self . lower_attrs ( & c. attrs ) ;
200- let exported_macros = c. exported_macros . iter ( ) . map ( |m| self . lower_macro_def ( m) ) . collect ( ) ;
201203 let body_ids = body_ids ( & self . bodies ) ;
202204
203205 hir:: Crate {
204206 module : module,
205207 attrs : attrs,
206208 span : c. span ,
207- exported_macros : exported_macros,
209+ exported_macros : hir :: HirVec :: from ( self . exported_macros ) ,
208210 items : self . items ,
209211 trait_items : self . trait_items ,
210212 impl_items : self . impl_items ,
@@ -1153,7 +1155,7 @@ impl<'a> LoweringContext<'a> {
11531155 bounds,
11541156 items)
11551157 }
1156- ItemKind :: Mac ( _ ) => panic ! ( "Shouldn't still be around" ) ,
1158+ ItemKind :: MacroDef ( .. ) | ItemKind :: Mac ( .. ) => panic ! ( "Shouldn't still be around" ) ,
11571159 }
11581160 }
11591161
@@ -1275,42 +1277,45 @@ impl<'a> LoweringContext<'a> {
12751277 }
12761278 }
12771279
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-
12881280 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+ }
12931287 }
1288+ ItemKind :: MacroDef ( ..) => return SmallVector :: new ( ) ,
1289+ _ => { }
12941290 }
12951291 SmallVector :: one ( hir:: ItemId { id : i. id } )
12961292 }
12971293
1298- pub fn lower_item ( & mut self , i : & Item ) -> hir:: Item {
1294+ pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
12991295 let mut name = i. ident . name ;
13001296 let attrs = self . lower_attrs ( & i. attrs ) ;
13011297 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+
13021307 let node = self . with_parent_def ( i. id , |this| {
13031308 this. lower_item_kind ( i. id , & mut name, & attrs, & mut vis, & i. node )
13041309 } ) ;
13051310
1306- hir:: Item {
1311+ Some ( hir:: Item {
13071312 id : i. id ,
13081313 name : name,
13091314 attrs : attrs,
13101315 node : node,
13111316 vis : vis,
13121317 span : i. span ,
1313- }
1318+ } )
13141319 }
13151320
13161321 fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem {
0 commit comments