@@ -13,7 +13,6 @@ use rustc_span::source_map::SourceMap;
1313use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
1414use rustc_span:: { Span , DUMMY_SP } ;
1515use smallvec:: smallvec;
16- use std:: cell:: RefCell ;
1716
1817struct ProcMacroDerive {
1918 id : NodeId ,
@@ -90,7 +89,7 @@ pub fn inject(
9089 return krate;
9190 }
9291
93- let decls = mk_decls ( & mut krate , & mut cx, & macros) ;
92+ let decls = mk_decls ( & mut cx, & macros) ;
9493 krate. items . push ( decls) ;
9594
9695 krate
@@ -289,15 +288,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
289288// // ...
290289// ];
291290// }
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 > {
301292 let expn_id = cx. resolver . expansion_for_ast_pass (
302293 DUMMY_SP ,
303294 AstPass :: ProcMacroHarness ,
@@ -316,26 +307,25 @@ fn mk_decls(
316307 let attr = Ident :: new ( sym:: attr, span) ;
317308 let bang = Ident :: new ( sym:: bang, span) ;
318309
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
322311 // that we generate expressions. The position of each NodeId
323312 // in the 'proc_macros' Vec corresponds to its position
324313 // in the static array that will be generated
325314 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| {
329319 cx. expr_path ( cx. path ( span, vec ! [ proc_macro, bridge, client, proc_macro_ty, method] ) )
330320 } ;
331321 macros
332322 . iter ( )
333323 . map ( |m| match m {
334324 ProcMacro :: Derive ( cd) => {
335- krate_ref . borrow_mut ( ) . proc_macros . push ( cd. id ) ;
325+ cx . resolver . declare_proc_macro ( cd. id ) ;
336326 cx. expr_call (
337327 span,
338- proc_macro_ty_method_path ( custom_derive) ,
328+ proc_macro_ty_method_path ( cx , custom_derive) ,
339329 vec ! [
340330 cx. expr_str( cd. span, cd. trait_name) ,
341331 cx. expr_vec_slice(
@@ -345,23 +335,23 @@ fn mk_decls(
345335 . map( |& s| cx. expr_str( cd. span, s) )
346336 . collect:: <Vec <_>>( ) ,
347337 ) ,
348- local_path( cd. span, cd. function_name) ,
338+ local_path( cx , cd. span, cd. function_name) ,
349339 ] ,
350340 )
351341 }
352342 ProcMacro :: Def ( ca) => {
353- krate_ref . borrow_mut ( ) . proc_macros . push ( ca. id ) ;
343+ cx . resolver . declare_proc_macro ( ca. id ) ;
354344 let ident = match ca. def_type {
355345 ProcMacroDefType :: Attr => attr,
356346 ProcMacroDefType :: Bang => bang,
357347 } ;
358348
359349 cx. expr_call (
360350 span,
361- proc_macro_ty_method_path ( ident) ,
351+ proc_macro_ty_method_path ( cx , ident) ,
362352 vec ! [
363353 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) ,
365355 ] ,
366356 )
367357 }
0 commit comments