Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/collector.rs')
| -rw-r--r-- | crates/hir-def/src/nameres/collector.rs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index 7fea46bee3..1c276e0d6f 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -74,19 +74,27 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T } let cfg_options = &krate.cfg_options; - let proc_macros = krate - .proc_macro - .iter() - .enumerate() - .map(|(idx, it)| { - // FIXME: a hacky way to create a Name from string. - let name = tt::Ident { text: it.name.clone(), id: tt::TokenId::unspecified() }; + let (proc_macros, proc_macro_err) = match &krate.proc_macro { + Ok(proc_macros) => { ( - name.as_name(), - ProcMacroExpander::new(def_map.krate, base_db::ProcMacroId(idx as u32)), + proc_macros + .iter() + .enumerate() + .map(|(idx, it)| { + // FIXME: a hacky way to create a Name from string. + let name = + tt::Ident { text: it.name.clone(), id: tt::TokenId::unspecified() }; + ( + name.as_name(), + ProcMacroExpander::new(def_map.krate, base_db::ProcMacroId(idx as u32)), + ) + }) + .collect(), + None, ) - }) - .collect(); + } + Err(e) => (Vec::new(), Some(e.clone())), + }; let is_proc_macro = krate.is_proc_macro; let mut collector = DefCollector { @@ -100,6 +108,7 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: DefMap, tree_id: T mod_dirs: FxHashMap::default(), cfg_options, proc_macros, + proc_macro_err, from_glob_import: Default::default(), skip_attrs: Default::default(), derive_helpers_in_scope: Default::default(), @@ -241,6 +250,7 @@ struct DefCollector<'a> { /// empty when proc. macro support is disabled (in which case we still do name resolution for /// them). proc_macros: Vec<(Name, ProcMacroExpander)>, + proc_macro_err: Option<String>, is_proc_macro: bool, from_glob_import: PerNsGlobImports, /// If we fail to resolve an attribute on a `ModItem`, we fall back to ignoring the attribute. @@ -1232,6 +1242,7 @@ impl DefCollector<'_> { self.def_map.diagnostics.push(DefDiagnostic::unresolved_proc_macro( directive.module_id, loc.kind, + self.proc_macro_err.clone(), )); return recollect_without(self); @@ -1283,7 +1294,11 @@ impl DefCollector<'_> { let diag = match err { hir_expand::ExpandError::UnresolvedProcMacro => { // Missing proc macros are non-fatal, so they are handled specially. - DefDiagnostic::unresolved_proc_macro(module_id, loc.kind.clone()) + DefDiagnostic::unresolved_proc_macro( + module_id, + loc.kind.clone(), + self.proc_macro_err.clone(), + ) } _ => DefDiagnostic::macro_error(module_id, loc.kind.clone(), err.to_string()), }; @@ -2097,6 +2112,7 @@ mod tests { mod_dirs: FxHashMap::default(), cfg_options: &CfgOptions::default(), proc_macros: Default::default(), + proc_macro_err: None, from_glob_import: Default::default(), skip_attrs: Default::default(), derive_helpers_in_scope: Default::default(), |