@@ -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 > ,
@@ -121,6 +122,7 @@ pub fn lower_crate(sess: &Session,
121
122
bodies : BTreeMap :: new ( ) ,
122
123
trait_impls : BTreeMap :: new ( ) ,
123
124
trait_default_impl : BTreeMap :: new ( ) ,
125
+ exported_macros : Vec :: new ( ) ,
124
126
loop_scopes : Vec :: new ( ) ,
125
127
is_in_loop_condition : false ,
126
128
type_def_lifetime_params : DefIdMap ( ) ,
@@ -170,9 +172,10 @@ impl<'a> LoweringContext<'a> {
170
172
171
173
impl < ' lcx , ' interner > Visitor < ' lcx > for ItemLowerer < ' lcx , ' interner > {
172
174
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
+ }
176
179
}
177
180
178
181
fn visit_trait_item ( & mut self , item : & ' lcx TraitItem ) {
@@ -195,14 +198,13 @@ impl<'a> LoweringContext<'a> {
195
198
196
199
let module = self . lower_mod ( & c. module ) ;
197
200
let attrs = self . lower_attrs ( & c. attrs ) ;
198
- let exported_macros = c. exported_macros . iter ( ) . map ( |m| self . lower_macro_def ( m) ) . collect ( ) ;
199
201
let body_ids = body_ids ( & self . bodies ) ;
200
202
201
203
hir:: Crate {
202
204
module : module,
203
205
attrs : attrs,
204
206
span : c. span ,
205
- exported_macros : exported_macros,
207
+ exported_macros : hir :: HirVec :: from ( self . exported_macros ) ,
206
208
items : self . items ,
207
209
trait_items : self . trait_items ,
208
210
impl_items : self . impl_items ,
@@ -1134,7 +1136,7 @@ impl<'a> LoweringContext<'a> {
1134
1136
bounds,
1135
1137
items)
1136
1138
}
1137
- ItemKind :: Mac ( _ ) => panic ! ( "Shouldn't still be around" ) ,
1139
+ ItemKind :: MacroDef ( .. ) | ItemKind :: Mac ( .. ) => panic ! ( "Shouldn't still be around" ) ,
1138
1140
}
1139
1141
}
1140
1142
@@ -1256,42 +1258,45 @@ impl<'a> LoweringContext<'a> {
1256
1258
}
1257
1259
}
1258
1260
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
-
1269
1261
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
+ }
1274
1268
}
1269
+ ItemKind :: MacroDef ( ..) => return SmallVector :: new ( ) ,
1270
+ _ => { }
1275
1271
}
1276
1272
SmallVector :: one ( hir:: ItemId { id : i. id } )
1277
1273
}
1278
1274
1279
- pub fn lower_item ( & mut self , i : & Item ) -> hir:: Item {
1275
+ pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
1280
1276
let mut name = i. ident . name ;
1281
1277
let attrs = self . lower_attrs ( & i. attrs ) ;
1282
1278
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
+
1283
1288
let node = self . with_parent_def ( i. id , |this| {
1284
1289
this. lower_item_kind ( i. id , & mut name, & attrs, & mut vis, & i. node )
1285
1290
} ) ;
1286
1291
1287
- hir:: Item {
1292
+ Some ( hir:: Item {
1288
1293
id : i. id ,
1289
1294
name : name,
1290
1295
attrs : attrs,
1291
1296
node : node,
1292
1297
vis : vis,
1293
1298
span : i. span ,
1294
- }
1299
+ } )
1295
1300
}
1296
1301
1297
1302
fn lower_foreign_item ( & mut self , i : & ForeignItem ) -> hir:: ForeignItem {
0 commit comments