@@ -65,6 +65,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr
6565 unexpanded_attribute_macros : Vec :: new ( ) ,
6666 mod_dirs : FxHashMap :: default ( ) ,
6767 cfg_options,
68+
69+ // FIXME: pass proc-macro from crate-graph
70+ proc_macros : Default :: default ( ) ,
6871 } ;
6972 collector. collect ( ) ;
7073 collector. finish ( )
@@ -123,6 +126,7 @@ struct DefCollector<'a> {
123126 unexpanded_attribute_macros : Vec < DeriveDirective > ,
124127 mod_dirs : FxHashMap < LocalModuleId , ModDir > ,
125128 cfg_options : & ' a CfgOptions ,
129+ proc_macros : Vec < ( Name , ProcMacroExpander ) > ,
126130}
127131
128132impl DefCollector < ' _ > {
@@ -178,6 +182,24 @@ impl DefCollector<'_> {
178182 for directive in unresolved_imports {
179183 self . record_resolved_import ( & directive)
180184 }
185+
186+ // Record proc-macros
187+ self . collect_proc_macro ( ) ;
188+ }
189+
190+ fn collect_proc_macro ( & mut self ) {
191+ let proc_macros = std:: mem:: take ( & mut self . proc_macros ) ;
192+ for ( name, expander) in proc_macros {
193+ let krate = self . def_map . krate ;
194+
195+ let macro_id = MacroDefId {
196+ ast_id : None ,
197+ krate : Some ( krate) ,
198+ kind : MacroDefKind :: CustomDerive ( expander) ,
199+ } ;
200+
201+ self . define_proc_macro ( name. clone ( ) , macro_id) ;
202+ }
181203 }
182204
183205 /// Define a macro with `macro_rules`.
@@ -801,7 +823,6 @@ impl ModCollector<'_, '_> {
801823 // in which case we don't add the invocation, just a single attribute
802824 // macro invocation
803825 self . collect_derives ( attrs, def) ;
804- self . collect_proc_macro ( attrs) ;
805826
806827 let name = def. name . clone ( ) ;
807828 let container = ContainerId :: ModuleId ( module) ;
@@ -878,28 +899,6 @@ impl ModCollector<'_, '_> {
878899 }
879900 }
880901
881- fn collect_proc_macro ( & mut self , attrs : & Attrs ) {
882- if let Some ( derive_subtree) = attrs. by_key ( "proc_macro_derive" ) . tt_values ( ) . next ( ) {
883- if let Some ( tt) = derive_subtree. token_trees . get ( 0 ) {
884- let ident = match & tt {
885- tt:: TokenTree :: Leaf ( tt:: Leaf :: Ident ( ident) ) => ident,
886- _ => return , // anything else would be an error (which we currently ignore)
887- } ;
888- let name = ident. as_name ( ) ;
889- let krate = self . def_collector . def_map . krate ;
890- let expander = ProcMacroExpander :: new ( krate) ;
891-
892- let macro_id = MacroDefId {
893- ast_id : None ,
894- krate : Some ( krate) ,
895- kind : MacroDefKind :: CustomDerive ( expander) ,
896- } ;
897-
898- self . def_collector . define_proc_macro ( name. clone ( ) , macro_id) ;
899- }
900- }
901- }
902-
903902 fn collect_macro ( & mut self , mac : & raw:: MacroData ) {
904903 let mut ast_id = AstIdWithPath :: new ( self . file_id , mac. ast_id , mac. path . clone ( ) ) ;
905904
@@ -1001,6 +1000,7 @@ mod tests {
10011000 unexpanded_attribute_macros : Vec :: new ( ) ,
10021001 mod_dirs : FxHashMap :: default ( ) ,
10031002 cfg_options : & CfgOptions :: default ( ) ,
1003+ proc_macros : Default :: default ( ) ,
10041004 } ;
10051005 collector. collect ( ) ;
10061006 collector. def_map
0 commit comments