aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/lib.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-16 14:48:03 +0100
committerJonas Schievink <[email protected]>2021-04-16 14:48:03 +0100
commitff858376aa4a974cda33a269b4c2d34cbda21bed (patch)
tree7bf88d82a5a31ed4d306e97cbcaab34d7f8d51a9 /crates/hir_def/src/lib.rs
parent75371eb0fa015ba8834ae2b66cda68eba5d83874 (diff)
Include path in `unresolved-macro-call` diagnostic
Diffstat (limited to 'crates/hir_def/src/lib.rs')
-rw-r--r--crates/hir_def/src/lib.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index ffee05500..000567d99 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -66,6 +66,7 @@ use hir_expand::{
66}; 66};
67use la_arena::Idx; 67use la_arena::Idx;
68use nameres::DefMap; 68use nameres::DefMap;
69use path::ModPath;
69use syntax::ast; 70use syntax::ast;
70 71
71use crate::builtin_type::BuiltinType; 72use crate::builtin_type::BuiltinType;
@@ -675,7 +676,9 @@ impl<T: ast::AstNode> AstIdWithPath<T> {
675 } 676 }
676} 677}
677 678
678pub struct UnresolvedMacro; 679pub struct UnresolvedMacro {
680 pub path: ModPath,
681}
679 682
680fn macro_call_as_call_id( 683fn macro_call_as_call_id(
681 call: &AstIdWithPath<ast::MacroCall>, 684 call: &AstIdWithPath<ast::MacroCall>,
@@ -684,7 +687,8 @@ fn macro_call_as_call_id(
684 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 687 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
685 error_sink: &mut dyn FnMut(mbe::ExpandError), 688 error_sink: &mut dyn FnMut(mbe::ExpandError),
686) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro> { 689) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro> {
687 let def: MacroDefId = resolver(call.path.clone()).ok_or(UnresolvedMacro)?; 690 let def: MacroDefId =
691 resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?;
688 692
689 let res = if let MacroDefKind::BuiltInEager(..) = def.kind { 693 let res = if let MacroDefKind::BuiltInEager(..) = def.kind {
690 let macro_call = InFile::new(call.ast_id.file_id, call.ast_id.to_node(db.upcast())); 694 let macro_call = InFile::new(call.ast_id.file_id, call.ast_id.to_node(db.upcast()));
@@ -714,8 +718,13 @@ fn derive_macro_as_call_id(
714 krate: CrateId, 718 krate: CrateId,
715 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 719 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
716) -> Result<MacroCallId, UnresolvedMacro> { 720) -> Result<MacroCallId, UnresolvedMacro> {
717 let def: MacroDefId = resolver(item_attr.path.clone()).ok_or(UnresolvedMacro)?; 721 let def: MacroDefId = resolver(item_attr.path.clone())
718 let last_segment = item_attr.path.segments().last().ok_or(UnresolvedMacro)?; 722 .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
723 let last_segment = item_attr
724 .path
725 .segments()
726 .last()
727 .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?;
719 let res = def 728 let res = def
720 .as_lazy_macro( 729 .as_lazy_macro(
721 db.upcast(), 730 db.upcast(),