@@ -74,19 +74,27 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
7474 }
7575
7676 let cfg_options = & krate. cfg_options ;
77- let proc_macros = krate
78- . proc_macro
79- . iter ( )
80- . enumerate ( )
81- . map ( |( idx, it) | {
82- // FIXME: a hacky way to create a Name from string.
83- let name = tt:: Ident { text : it. name . clone ( ) , id : tt:: TokenId :: unspecified ( ) } ;
77+ let ( proc_macros, proc_macro_err) = match & krate. proc_macro {
78+ Ok ( proc_macros) => {
8479 (
85- name. as_name ( ) ,
86- ProcMacroExpander :: new ( def_map. krate , base_db:: ProcMacroId ( idx as u32 ) ) ,
80+ proc_macros
81+ . iter ( )
82+ . enumerate ( )
83+ . map ( |( idx, it) | {
84+ // FIXME: a hacky way to create a Name from string.
85+ let name =
86+ tt:: Ident { text : it. name . clone ( ) , id : tt:: TokenId :: unspecified ( ) } ;
87+ (
88+ name. as_name ( ) ,
89+ ProcMacroExpander :: new ( def_map. krate , base_db:: ProcMacroId ( idx as u32 ) ) ,
90+ )
91+ } )
92+ . collect ( ) ,
93+ None ,
8794 )
88- } )
89- . collect ( ) ;
95+ }
96+ Err ( e) => ( Vec :: new ( ) , Some ( e. clone ( ) ) ) ,
97+ } ;
9098 let is_proc_macro = krate. is_proc_macro ;
9199
92100 let mut collector = DefCollector {
@@ -100,6 +108,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
100108 mod_dirs : FxHashMap :: default ( ) ,
101109 cfg_options,
102110 proc_macros,
111+ proc_macro_err,
103112 from_glob_import : Default :: default ( ) ,
104113 skip_attrs : Default :: default ( ) ,
105114 derive_helpers_in_scope : Default :: default ( ) ,
@@ -241,6 +250,7 @@ struct DefCollector<'a> {
241250 /// empty when proc. macro support is disabled (in which case we still do name resolution for
242251 /// them).
243252 proc_macros : Vec < ( Name , ProcMacroExpander ) > ,
253+ proc_macro_err : Option < String > ,
244254 is_proc_macro : bool ,
245255 from_glob_import : PerNsGlobImports ,
246256 /// If we fail to resolve an attribute on a `ModItem`, we fall back to ignoring the attribute.
@@ -1232,6 +1242,7 @@ impl DefCollector<'_> {
12321242 self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_proc_macro (
12331243 directive. module_id ,
12341244 loc. kind ,
1245+ self . proc_macro_err . clone ( ) ,
12351246 ) ) ;
12361247
12371248 return recollect_without ( self ) ;
@@ -1283,7 +1294,11 @@ impl DefCollector<'_> {
12831294 let diag = match err {
12841295 hir_expand:: ExpandError :: UnresolvedProcMacro => {
12851296 // Missing proc macros are non-fatal, so they are handled specially.
1286- DefDiagnostic :: unresolved_proc_macro ( module_id, loc. kind . clone ( ) )
1297+ DefDiagnostic :: unresolved_proc_macro (
1298+ module_id,
1299+ loc. kind . clone ( ) ,
1300+ self . proc_macro_err . clone ( ) ,
1301+ )
12871302 }
12881303 _ => DefDiagnostic :: macro_error ( module_id, loc. kind . clone ( ) , err. to_string ( ) ) ,
12891304 } ;
@@ -2097,6 +2112,7 @@ mod tests {
20972112 mod_dirs : FxHashMap :: default ( ) ,
20982113 cfg_options : & CfgOptions :: default ( ) ,
20992114 proc_macros : Default :: default ( ) ,
2115+ proc_macro_err : None ,
21002116 from_glob_import : Default :: default ( ) ,
21012117 skip_attrs : Default :: default ( ) ,
21022118 derive_helpers_in_scope : Default :: default ( ) ,
0 commit comments