@@ -65,6 +65,9 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr
65
65
unexpanded_attribute_macros : Vec :: new ( ) ,
66
66
mod_dirs : FxHashMap :: default ( ) ,
67
67
cfg_options,
68
+
69
+ // FIXME: pass proc-macro from crate-graph
70
+ proc_macros : Default :: default ( ) ,
68
71
} ;
69
72
collector. collect ( ) ;
70
73
collector. finish ( )
@@ -123,6 +126,7 @@ struct DefCollector<'a> {
123
126
unexpanded_attribute_macros : Vec < DeriveDirective > ,
124
127
mod_dirs : FxHashMap < LocalModuleId , ModDir > ,
125
128
cfg_options : & ' a CfgOptions ,
129
+ proc_macros : Vec < ( Name , ProcMacroExpander ) > ,
126
130
}
127
131
128
132
impl DefCollector < ' _ > {
@@ -178,6 +182,24 @@ impl DefCollector<'_> {
178
182
for directive in unresolved_imports {
179
183
self . record_resolved_import ( & directive)
180
184
}
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
+ }
181
203
}
182
204
183
205
/// Define a macro with `macro_rules`.
@@ -801,7 +823,6 @@ impl ModCollector<'_, '_> {
801
823
// in which case we don't add the invocation, just a single attribute
802
824
// macro invocation
803
825
self . collect_derives ( attrs, def) ;
804
- self . collect_proc_macro ( attrs) ;
805
826
806
827
let name = def. name . clone ( ) ;
807
828
let container = ContainerId :: ModuleId ( module) ;
@@ -878,28 +899,6 @@ impl ModCollector<'_, '_> {
878
899
}
879
900
}
880
901
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
-
903
902
fn collect_macro ( & mut self , mac : & raw:: MacroData ) {
904
903
let mut ast_id = AstIdWithPath :: new ( self . file_id , mac. ast_id , mac. path . clone ( ) ) ;
905
904
@@ -1001,6 +1000,7 @@ mod tests {
1001
1000
unexpanded_attribute_macros : Vec :: new ( ) ,
1002
1001
mod_dirs : FxHashMap :: default ( ) ,
1003
1002
cfg_options : & CfgOptions :: default ( ) ,
1003
+ proc_macros : Default :: default ( ) ,
1004
1004
} ;
1005
1005
collector. collect ( ) ;
1006
1006
collector. def_map
0 commit comments