aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/nameres')
-rw-r--r--crates/hir_def/src/nameres/collector.rs33
-rw-r--r--crates/hir_def/src/nameres/tests/incremental.rs4
2 files changed, 34 insertions, 3 deletions
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::{
13 builtin_macro::find_builtin_macro, 13 builtin_macro::find_builtin_macro,
14 name::{AsName, Name}, 14 name::{AsName, Name},
15 proc_macro::ProcMacroExpander, 15 proc_macro::ProcMacroExpander,
16 HirFileId, MacroCallId, MacroDefId, MacroDefKind, 16 HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
17}; 17};
18use hir_expand::{InFile, MacroCallLoc}; 18use hir_expand::{InFile, MacroCallLoc};
19use rustc_hash::{FxHashMap, FxHashSet}; 19use rustc_hash::{FxHashMap, FxHashSet};
@@ -860,6 +860,37 @@ impl DefCollector<'_> {
860 } 860 }
861 861
862 fn finish(mut self) -> CrateDefMap { 862 fn finish(mut self) -> CrateDefMap {
863 // Emit diagnostics for all remaining unexpanded macros.
864
865 for directive in &self.unexpanded_macros {
866 let mut error = None;
867 directive.ast_id.as_call_id_with_errors(
868 self.db,
869 self.def_map.krate,
870 |path| {
871 let resolved_res = self.def_map.resolve_path_fp_with_macro(
872 self.db,
873 ResolveMode::Other,
874 directive.module_id,
875 &path,
876 BuiltinShadowMode::Module,
877 );
878 resolved_res.resolved_def.take_macros()
879 },
880 &mut |e| {
881 error.get_or_insert(e);
882 },
883 );
884
885 if let Some(err) = error {
886 self.def_map.diagnostics.push(DefDiagnostic::macro_error(
887 directive.module_id,
888 MacroCallKind::FnLike(directive.ast_id.ast_id),
889 err.to_string(),
890 ));
891 }
892 }
893
863 // Emit diagnostics for all remaining unresolved imports. 894 // Emit diagnostics for all remaining unresolved imports.
864 895
865 // We'd like to avoid emitting a diagnostics avalanche when some `extern crate` doesn't 896 // We'd like to avoid emitting a diagnostics avalanche when some `extern crate` doesn't
diff --git a/crates/hir_def/src/nameres/tests/incremental.rs b/crates/hir_def/src/nameres/tests/incremental.rs
index 8981fa7c9..509e1bbbc 100644
--- a/crates/hir_def/src/nameres/tests/incremental.rs
+++ b/crates/hir_def/src/nameres/tests/incremental.rs
@@ -28,7 +28,7 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
28 check_def_map_is_not_recomputed( 28 check_def_map_is_not_recomputed(
29 r" 29 r"
30 //- /lib.rs 30 //- /lib.rs
31 mod foo;<|> 31 mod foo;$0
32 32
33 use crate::foo::bar::Baz; 33 use crate::foo::bar::Baz;
34 34
@@ -81,7 +81,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
81 pub mod bar; 81 pub mod bar;
82 82
83 //- /foo/bar.rs 83 //- /foo/bar.rs
84 <|> 84 $0
85 m!(X); 85 m!(X);
86 ", 86 ",
87 ); 87 );