aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/nameres.rs')
-rw-r--r--crates/hir_def/src/nameres.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index f92232eb3..003d668ca 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -343,6 +343,18 @@ impl DefMap {
343 Some(self.block?.parent) 343 Some(self.block?.parent)
344 } 344 }
345 345
346 /// Returns the module containing `local_mod`, either the parent `mod`, or the module containing
347 /// the block, if `self` corresponds to a block expression.
348 pub fn containing_module(&self, local_mod: LocalModuleId) -> Option<ModuleId> {
349 match &self[local_mod].parent {
350 Some(parent) => Some(self.module_id(*parent)),
351 None => match &self.block {
352 Some(block) => Some(block.parent),
353 None => None,
354 },
355 }
356 }
357
346 // FIXME: this can use some more human-readable format (ideally, an IR 358 // FIXME: this can use some more human-readable format (ideally, an IR
347 // even), as this should be a great debugging aid. 359 // even), as this should be a great debugging aid.
348 pub fn dump(&self, db: &dyn DefDatabase) -> String { 360 pub fn dump(&self, db: &dyn DefDatabase) -> String {
@@ -417,6 +429,8 @@ mod diagnostics {
417 429
418 UnresolvedProcMacro { ast: MacroCallKind }, 430 UnresolvedProcMacro { ast: MacroCallKind },
419 431
432 UnresolvedMacroCall { ast: AstId<ast::MacroCall> },
433
420 MacroError { ast: MacroCallKind, message: String }, 434 MacroError { ast: MacroCallKind, message: String },
421 } 435 }
422 436
@@ -477,6 +491,13 @@ mod diagnostics {
477 Self { in_module: container, kind: DiagnosticKind::MacroError { ast, message } } 491 Self { in_module: container, kind: DiagnosticKind::MacroError { ast, message } }
478 } 492 }
479 493
494 pub(super) fn unresolved_macro_call(
495 container: LocalModuleId,
496 ast: AstId<ast::MacroCall>,
497 ) -> Self {
498 Self { in_module: container, kind: DiagnosticKind::UnresolvedMacroCall { ast } }
499 }
500
480 pub(super) fn add_to( 501 pub(super) fn add_to(
481 &self, 502 &self,
482 db: &dyn DefDatabase, 503 db: &dyn DefDatabase,
@@ -589,6 +610,11 @@ mod diagnostics {
589 }); 610 });
590 } 611 }
591 612
613 DiagnosticKind::UnresolvedMacroCall { ast } => {
614 let node = ast.to_node(db.upcast());
615 sink.push(UnresolvedMacroCall { file: ast.file_id, node: AstPtr::new(&node) });
616 }
617
592 DiagnosticKind::MacroError { ast, message } => { 618 DiagnosticKind::MacroError { ast, message } => {
593 let (file, ast) = match ast { 619 let (file, ast) = match ast {
594 MacroCallKind::FnLike(ast) => { 620 MacroCallKind::FnLike(ast) => {