@@ -74,19 +74,27 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
74
74
}
75
75
76
76
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) => {
84
79
(
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 ,
87
94
)
88
- } )
89
- . collect ( ) ;
95
+ }
96
+ Err ( e) => ( Vec :: new ( ) , Some ( e. clone ( ) ) ) ,
97
+ } ;
90
98
let is_proc_macro = krate. is_proc_macro ;
91
99
92
100
let mut collector = DefCollector {
@@ -100,6 +108,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T
100
108
mod_dirs : FxHashMap :: default ( ) ,
101
109
cfg_options,
102
110
proc_macros,
111
+ proc_macro_err,
103
112
from_glob_import : Default :: default ( ) ,
104
113
skip_attrs : Default :: default ( ) ,
105
114
derive_helpers_in_scope : Default :: default ( ) ,
@@ -241,6 +250,7 @@ struct DefCollector<'a> {
241
250
/// empty when proc. macro support is disabled (in which case we still do name resolution for
242
251
/// them).
243
252
proc_macros : Vec < ( Name , ProcMacroExpander ) > ,
253
+ proc_macro_err : Option < String > ,
244
254
is_proc_macro : bool ,
245
255
from_glob_import : PerNsGlobImports ,
246
256
/// If we fail to resolve an attribute on a `ModItem`, we fall back to ignoring the attribute.
@@ -1232,6 +1242,7 @@ impl DefCollector<'_> {
1232
1242
self . def_map . diagnostics . push ( DefDiagnostic :: unresolved_proc_macro (
1233
1243
directive. module_id ,
1234
1244
loc. kind ,
1245
+ self . proc_macro_err . clone ( ) ,
1235
1246
) ) ;
1236
1247
1237
1248
return recollect_without ( self ) ;
@@ -1283,7 +1294,11 @@ impl DefCollector<'_> {
1283
1294
let diag = match err {
1284
1295
hir_expand:: ExpandError :: UnresolvedProcMacro => {
1285
1296
// 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
+ )
1287
1302
}
1288
1303
_ => DefDiagnostic :: macro_error ( module_id, loc. kind . clone ( ) , err. to_string ( ) ) ,
1289
1304
} ;
@@ -2097,6 +2112,7 @@ mod tests {
2097
2112
mod_dirs : FxHashMap :: default ( ) ,
2098
2113
cfg_options : & CfgOptions :: default ( ) ,
2099
2114
proc_macros : Default :: default ( ) ,
2115
+ proc_macro_err : None ,
2100
2116
from_glob_import : Default :: default ( ) ,
2101
2117
skip_attrs : Default :: default ( ) ,
2102
2118
derive_helpers_in_scope : Default :: default ( ) ,
0 commit comments