@@ -13,7 +13,6 @@ use rustc_span::source_map::SourceMap;
13
13
use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
14
14
use rustc_span:: { Span , DUMMY_SP } ;
15
15
use smallvec:: smallvec;
16
- use std:: cell:: RefCell ;
17
16
18
17
struct ProcMacroDerive {
19
18
id : NodeId ,
@@ -90,7 +89,7 @@ pub fn inject(
90
89
return krate;
91
90
}
92
91
93
- let decls = mk_decls ( & mut krate , & mut cx, & macros) ;
92
+ let decls = mk_decls ( & mut cx, & macros) ;
94
93
krate. items . push ( decls) ;
95
94
96
95
krate
@@ -289,15 +288,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
289
288
// // ...
290
289
// ];
291
290
// }
292
- fn mk_decls (
293
- ast_krate : & mut ast:: Crate ,
294
- cx : & mut ExtCtxt < ' _ > ,
295
- macros : & [ ProcMacro ] ,
296
- ) -> P < ast:: Item > {
297
- // We're the ones filling in this Vec,
298
- // so it should be empty to start with
299
- assert ! ( ast_krate. proc_macros. is_empty( ) ) ;
300
-
291
+ fn mk_decls ( cx : & mut ExtCtxt < ' _ > , macros : & [ ProcMacro ] ) -> P < ast:: Item > {
301
292
let expn_id = cx. resolver . expansion_for_ast_pass (
302
293
DUMMY_SP ,
303
294
AstPass :: ProcMacroHarness ,
@@ -316,26 +307,25 @@ fn mk_decls(
316
307
let attr = Ident :: new ( sym:: attr, span) ;
317
308
let bang = Ident :: new ( sym:: bang, span) ;
318
309
319
- let krate_ref = RefCell :: new ( ast_krate) ;
320
-
321
- // We add NodeIds to 'krate.proc_macros' in the order
310
+ // We add NodeIds to 'resolver.proc_macros' in the order
322
311
// that we generate expressions. The position of each NodeId
323
312
// in the 'proc_macros' Vec corresponds to its position
324
313
// in the static array that will be generated
325
314
let decls = {
326
- let local_path =
327
- |sp : Span , name| cx. expr_path ( cx. path ( sp. with_ctxt ( span. ctxt ( ) ) , vec ! [ name] ) ) ;
328
- let proc_macro_ty_method_path = |method| {
315
+ let local_path = |cx : & ExtCtxt < ' _ > , sp : Span , name| {
316
+ cx. expr_path ( cx. path ( sp. with_ctxt ( span. ctxt ( ) ) , vec ! [ name] ) )
317
+ } ;
318
+ let proc_macro_ty_method_path = |cx : & ExtCtxt < ' _ > , method| {
329
319
cx. expr_path ( cx. path ( span, vec ! [ proc_macro, bridge, client, proc_macro_ty, method] ) )
330
320
} ;
331
321
macros
332
322
. iter ( )
333
323
. map ( |m| match m {
334
324
ProcMacro :: Derive ( cd) => {
335
- krate_ref . borrow_mut ( ) . proc_macros . push ( cd. id ) ;
325
+ cx . resolver . declare_proc_macro ( cd. id ) ;
336
326
cx. expr_call (
337
327
span,
338
- proc_macro_ty_method_path ( custom_derive) ,
328
+ proc_macro_ty_method_path ( cx , custom_derive) ,
339
329
vec ! [
340
330
cx. expr_str( cd. span, cd. trait_name) ,
341
331
cx. expr_vec_slice(
@@ -345,23 +335,23 @@ fn mk_decls(
345
335
. map( |& s| cx. expr_str( cd. span, s) )
346
336
. collect:: <Vec <_>>( ) ,
347
337
) ,
348
- local_path( cd. span, cd. function_name) ,
338
+ local_path( cx , cd. span, cd. function_name) ,
349
339
] ,
350
340
)
351
341
}
352
342
ProcMacro :: Def ( ca) => {
353
- krate_ref . borrow_mut ( ) . proc_macros . push ( ca. id ) ;
343
+ cx . resolver . declare_proc_macro ( ca. id ) ;
354
344
let ident = match ca. def_type {
355
345
ProcMacroDefType :: Attr => attr,
356
346
ProcMacroDefType :: Bang => bang,
357
347
} ;
358
348
359
349
cx. expr_call (
360
350
span,
361
- proc_macro_ty_method_path ( ident) ,
351
+ proc_macro_ty_method_path ( cx , ident) ,
362
352
vec ! [
363
353
cx. expr_str( ca. span, ca. function_name. name) ,
364
- local_path( ca. span, ca. function_name) ,
354
+ local_path( cx , ca. span, ca. function_name) ,
365
355
] ,
366
356
)
367
357
}
0 commit comments