From 3cb7c8b548883ed8dcf589193df058dcda0a5c64 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 5 Jan 2021 15:42:43 +0100 Subject: Emit diagnostics for unresolved item-level macros --- crates/hir_def/src/nameres/collector.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index a636ec77d..77017e4ea 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -13,7 +13,7 @@ use hir_expand::{ builtin_macro::find_builtin_macro, name::{AsName, Name}, proc_macro::ProcMacroExpander, - HirFileId, MacroCallId, MacroDefId, MacroDefKind, + HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, }; use hir_expand::{InFile, MacroCallLoc}; use rustc_hash::{FxHashMap, FxHashSet}; @@ -860,6 +860,37 @@ impl DefCollector<'_> { } fn finish(mut self) -> CrateDefMap { + // Emit diagnostics for all remaining unexpanded macros. + + for directive in &self.unexpanded_macros { + let mut error = None; + directive.ast_id.as_call_id_with_errors( + self.db, + self.def_map.krate, + |path| { + let resolved_res = self.def_map.resolve_path_fp_with_macro( + self.db, + ResolveMode::Other, + directive.module_id, + &path, + BuiltinShadowMode::Module, + ); + resolved_res.resolved_def.take_macros() + }, + &mut |e| { + error.get_or_insert(e); + }, + ); + + if let Some(err) = error { + self.def_map.diagnostics.push(DefDiagnostic::macro_error( + directive.module_id, + MacroCallKind::FnLike(directive.ast_id.ast_id), + err.to_string(), + )); + } + } + // Emit diagnostics for all remaining unresolved imports. // We'd like to avoid emitting a diagnostics avalanche when some `extern crate` doesn't -- cgit v1.2.3