diff options
Diffstat (limited to 'crates/hir_def/src/lib.rs')
-rw-r--r-- | crates/hir_def/src/lib.rs | 17 |
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 | }; |
67 | use la_arena::Idx; | 67 | use la_arena::Idx; |
68 | use nameres::DefMap; | 68 | use nameres::DefMap; |
69 | use path::ModPath; | ||
69 | use syntax::ast; | 70 | use syntax::ast; |
70 | 71 | ||
71 | use crate::builtin_type::BuiltinType; | 72 | use crate::builtin_type::BuiltinType; |
@@ -675,7 +676,9 @@ impl<T: ast::AstNode> AstIdWithPath<T> { | |||
675 | } | 676 | } |
676 | } | 677 | } |
677 | 678 | ||
678 | pub struct UnresolvedMacro; | 679 | pub struct UnresolvedMacro { |
680 | pub path: ModPath, | ||
681 | } | ||
679 | 682 | ||
680 | fn macro_call_as_call_id( | 683 | fn 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(), |