@@ -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 > ,
@@ -121,6 +122,7 @@ pub fn lower_crate(sess: &Session,
121122 bodies : BTreeMap :: new ( ) ,
122123 trait_impls : BTreeMap :: new ( ) ,
123124 trait_default_impl : BTreeMap :: new ( ) ,
125+ exported_macros : Vec :: new ( ) ,
124126 loop_scopes : Vec :: new ( ) ,
125127 is_in_loop_condition : false ,
126128 type_def_lifetime_params : DefIdMap ( ) ,
@@ -170,9 +172,10 @@ impl<'a> LoweringContext<'a> {
170172
171173 impl < ' lcx , ' interner > Visitor < ' lcx > for ItemLowerer < ' lcx , ' interner > {
172174 fn visit_item ( & mut self , item : & ' lcx Item ) {
173- let hir_item = self . lctx . lower_item ( item) ;
174- self . lctx . items . insert ( item. id , hir_item) ;
175- visit:: walk_item ( self , item) ;
175+ if let Some ( hir_item) = self . lctx . lower_item ( item) {
176+ self . lctx . items . insert ( item. id , hir_item) ;
177+ visit:: walk_item ( self , item) ;
178+ }
176179 }
177180
178181 fn visit_trait_item ( & mut self , item : & ' lcx TraitItem ) {
@@ -195,14 +198,13 @@ impl<'a> LoweringContext<'a> {
195198
196199 let module = self . lower_mod ( & c. module ) ;
197200 let attrs = self . lower_attrs ( & c. attrs ) ;
198- let exported_macros = c. exported_macros . iter ( ) . map ( |m| self . lower_macro_def ( m) ) . collect ( ) ;
199201 let body_ids = body_ids ( & self . bodies ) ;
200202
201203 hir:: Crate {
202204 module : module,
203205 attrs : attrs,
204206 span : c. span ,
205- exported_macros : exported_macros,
207+ exported_macros : hir :: HirVec :: from ( self . exported_macros ) ,
206208 items : self . items ,
207209 trait_items : self . trait_items ,
208210 impl_items : self . impl_items ,
@@ -1134,7 +1136,7 @@ impl<'a> LoweringContext<'a> {
11341136 bounds,
11351137 items)
11361138 }
1137- ItemKind :: Mac ( _ ) => panic ! ( "Shouldn't still be around" ) ,
1139+ ItemKind :: MacroDef ( .. ) | ItemKind :: Mac ( .. ) => panic ! ( "Shouldn't still be around" ) ,
11381140 }
11391141 }
11401142
@@ -1256,42 +1258,45 @@ impl<'a> LoweringContext<'a> {
12561258 }
12571259 }
12581260
1259- fn lower_macro_def ( & mut self , m : & MacroDef ) -> hir:: MacroDef {
1260- hir:: MacroDef {
1261- name : m. ident . name ,
1262- attrs : self . lower_attrs ( & m. attrs ) ,
1263- id : m. id ,
1264- span : m. span ,
1265- body : m. body . clone ( ) . into ( ) ,
1266- }
1267- }
1268-
12691261 fn lower_item_id ( & mut self , i : & Item ) -> SmallVector < hir:: ItemId > {
1270- if let ItemKind :: Use ( ref view_path) = i. node {
1271- if let ViewPathList ( _, ref imports) = view_path. node {
1272- return iter:: once ( i. id ) . chain ( imports. iter ( ) . map ( |import| import. node . id ) )
1273- . map ( |id| hir:: ItemId { id : id } ) . collect ( ) ;
1262+ match i. node {
1263+ ItemKind :: Use ( ref view_path) => {
1264+ if let ViewPathList ( _, ref imports) = view_path. node {
1265+ return iter:: once ( i. id ) . chain ( imports. iter ( ) . map ( |import| import. node . id ) )
1266+ . map ( |id| hir:: ItemId { id : id } ) . collect ( ) ;
1267+ }
12741268 }
1269+ ItemKind :: MacroDef ( ..) => return SmallVector :: new ( ) ,
1270+ _ => { }
12751271 }
12761272 SmallVector :: one ( hir:: ItemId { id : i. id } )
12771273 }
12781274
1279- pub fn lower_item ( & mut self , i : & Item ) -> hir:: Item {
1275+ pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
12801276 let mut name = i. ident . name ;
12811277 let attrs = self . lower_attrs ( & i. attrs ) ;
12821278 let mut vis = self . lower_visibility ( & i. vis ) ;
1279+ if let ItemKind :: MacroDef ( ref tts) = i. node {
1280+ if i. attrs . iter ( ) . any ( |attr| attr. name ( ) == "macro_export" ) {
1281+ self . exported_macros . push ( hir:: MacroDef {
1282+ name : name, attrs : attrs, id : i. id , span : i. span , body : tts. clone ( ) . into ( ) ,
1283+ } ) ;
1284+ }
1285+ return None ;
1286+ }
1287+
12831288 let node = self . with_parent_def ( i. id , |this| {
12841289 this. lower_item_kind ( i. id , & mut name, & attrs, & mut vis, & i. node )
12851290 } ) ;
12861291
1287- hir:: Item {
1292+ Some ( hir:: Item {
12881293 id : i. id ,
12891294 name : name,
12901295 attrs : attrs,
12911296 node : node,
12921297 vis : vis,
12931298 span : i. span ,
1294- }
1299+ } )
12951300 }
12961301
12971302 fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem {
0 commit comments