From ff858376aa4a974cda33a269b4c2d34cbda21bed Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 16 Apr 2021 15:48:03 +0200 Subject: Include path in `unresolved-macro-call` diagnostic --- crates/hir_def/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'crates/hir_def/src/lib.rs') 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::{ }; use la_arena::Idx; use nameres::DefMap; +use path::ModPath; use syntax::ast; use crate::builtin_type::BuiltinType; @@ -675,7 +676,9 @@ impl AstIdWithPath { } } -pub struct UnresolvedMacro; +pub struct UnresolvedMacro { + pub path: ModPath, +} fn macro_call_as_call_id( call: &AstIdWithPath, @@ -684,7 +687,8 @@ fn macro_call_as_call_id( resolver: impl Fn(path::ModPath) -> Option, error_sink: &mut dyn FnMut(mbe::ExpandError), ) -> Result, UnresolvedMacro> { - let def: MacroDefId = resolver(call.path.clone()).ok_or(UnresolvedMacro)?; + let def: MacroDefId = + resolver(call.path.clone()).ok_or_else(|| UnresolvedMacro { path: call.path.clone() })?; let res = if let MacroDefKind::BuiltInEager(..) = def.kind { 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( krate: CrateId, resolver: impl Fn(path::ModPath) -> Option, ) -> Result { - let def: MacroDefId = resolver(item_attr.path.clone()).ok_or(UnresolvedMacro)?; - let last_segment = item_attr.path.segments().last().ok_or(UnresolvedMacro)?; + let def: MacroDefId = resolver(item_attr.path.clone()) + .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?; + let last_segment = item_attr + .path + .segments() + .last() + .ok_or_else(|| UnresolvedMacro { path: item_attr.path.clone() })?; let res = def .as_lazy_macro( db.upcast(), -- cgit v1.2.3