diff options
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r-- | crates/hir_def/src/body/lower.rs | 8 | ||||
-rw-r--r-- | crates/hir_def/src/body/tests.rs | 2 | ||||
-rw-r--r-- | crates/hir_def/src/diagnostics.rs | 5 | ||||
-rw-r--r-- | crates/hir_def/src/lib.rs | 17 | ||||
-rw-r--r-- | crates/hir_def/src/nameres.rs | 13 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 9 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/diagnostics.rs | 4 |
7 files changed, 39 insertions, 19 deletions
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index ed07d6928..c0b0b7841 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs | |||
@@ -568,9 +568,13 @@ impl ExprCollector<'_> { | |||
568 | 568 | ||
569 | let res = match res { | 569 | let res = match res { |
570 | Ok(res) => res, | 570 | Ok(res) => res, |
571 | Err(UnresolvedMacro) => { | 571 | Err(UnresolvedMacro { path }) => { |
572 | self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedMacroCall( | 572 | self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedMacroCall( |
573 | UnresolvedMacroCall { file: outer_file, node: syntax_ptr.cast().unwrap() }, | 573 | UnresolvedMacroCall { |
574 | file: outer_file, | ||
575 | node: syntax_ptr.cast().unwrap(), | ||
576 | path, | ||
577 | }, | ||
574 | )); | 578 | )); |
575 | collector(self, None); | 579 | collector(self, None); |
576 | return; | 580 | return; |
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs index c1d3e998f..63f5fe88d 100644 --- a/crates/hir_def/src/body/tests.rs +++ b/crates/hir_def/src/body/tests.rs | |||
@@ -180,7 +180,7 @@ fn unresolved_macro_diag() { | |||
180 | r#" | 180 | r#" |
181 | fn f() { | 181 | fn f() { |
182 | m!(); | 182 | m!(); |
183 | //^^^^ unresolved macro call | 183 | //^^^^ unresolved macro `m!` |
184 | } | 184 | } |
185 | "#, | 185 | "#, |
186 | ); | 186 | ); |
diff --git a/crates/hir_def/src/diagnostics.rs b/crates/hir_def/src/diagnostics.rs index 97abf8653..a71ae2668 100644 --- a/crates/hir_def/src/diagnostics.rs +++ b/crates/hir_def/src/diagnostics.rs | |||
@@ -8,7 +8,7 @@ use hir_expand::diagnostics::{Diagnostic, DiagnosticCode, DiagnosticSink}; | |||
8 | use hir_expand::{HirFileId, InFile}; | 8 | use hir_expand::{HirFileId, InFile}; |
9 | use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange}; | 9 | use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange}; |
10 | 10 | ||
11 | use crate::{db::DefDatabase, DefWithBodyId}; | 11 | use crate::{db::DefDatabase, path::ModPath, DefWithBodyId}; |
12 | 12 | ||
13 | pub fn validate_body(db: &dyn DefDatabase, owner: DefWithBodyId, sink: &mut DiagnosticSink<'_>) { | 13 | pub fn validate_body(db: &dyn DefDatabase, owner: DefWithBodyId, sink: &mut DiagnosticSink<'_>) { |
14 | let source_map = db.body_with_source_map(owner).1; | 14 | let source_map = db.body_with_source_map(owner).1; |
@@ -103,6 +103,7 @@ impl Diagnostic for UnresolvedImport { | |||
103 | pub struct UnresolvedMacroCall { | 103 | pub struct UnresolvedMacroCall { |
104 | pub file: HirFileId, | 104 | pub file: HirFileId, |
105 | pub node: AstPtr<ast::MacroCall>, | 105 | pub node: AstPtr<ast::MacroCall>, |
106 | pub path: ModPath, | ||
106 | } | 107 | } |
107 | 108 | ||
108 | impl Diagnostic for UnresolvedMacroCall { | 109 | impl Diagnostic for UnresolvedMacroCall { |
@@ -110,7 +111,7 @@ impl Diagnostic for UnresolvedMacroCall { | |||
110 | DiagnosticCode("unresolved-macro-call") | 111 | DiagnosticCode("unresolved-macro-call") |
111 | } | 112 | } |
112 | fn message(&self) -> String { | 113 | fn message(&self) -> String { |
113 | "unresolved macro call".to_string() | 114 | format!("unresolved macro `{}!`", self.path) |
114 | } | 115 | } |
115 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | 116 | fn display_source(&self) -> InFile<SyntaxNodePtr> { |
116 | InFile::new(self.file, self.node.clone().into()) | 117 | InFile::new(self.file, self.node.clone().into()) |
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(), |
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 9e181751c..542f190a1 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -481,7 +481,7 @@ mod diagnostics { | |||
481 | 481 | ||
482 | UnresolvedProcMacro { ast: MacroCallKind }, | 482 | UnresolvedProcMacro { ast: MacroCallKind }, |
483 | 483 | ||
484 | UnresolvedMacroCall { ast: AstId<ast::MacroCall> }, | 484 | UnresolvedMacroCall { ast: AstId<ast::MacroCall>, path: ModPath }, |
485 | 485 | ||
486 | MacroError { ast: MacroCallKind, message: String }, | 486 | MacroError { ast: MacroCallKind, message: String }, |
487 | } | 487 | } |
@@ -546,8 +546,9 @@ mod diagnostics { | |||
546 | pub(super) fn unresolved_macro_call( | 546 | pub(super) fn unresolved_macro_call( |
547 | container: LocalModuleId, | 547 | container: LocalModuleId, |
548 | ast: AstId<ast::MacroCall>, | 548 | ast: AstId<ast::MacroCall>, |
549 | path: ModPath, | ||
549 | ) -> Self { | 550 | ) -> Self { |
550 | Self { in_module: container, kind: DiagnosticKind::UnresolvedMacroCall { ast } } | 551 | Self { in_module: container, kind: DiagnosticKind::UnresolvedMacroCall { ast, path } } |
551 | } | 552 | } |
552 | 553 | ||
553 | pub(super) fn add_to( | 554 | pub(super) fn add_to( |
@@ -662,9 +663,13 @@ mod diagnostics { | |||
662 | }); | 663 | }); |
663 | } | 664 | } |
664 | 665 | ||
665 | DiagnosticKind::UnresolvedMacroCall { ast } => { | 666 | DiagnosticKind::UnresolvedMacroCall { ast, path } => { |
666 | let node = ast.to_node(db.upcast()); | 667 | let node = ast.to_node(db.upcast()); |
667 | sink.push(UnresolvedMacroCall { file: ast.file_id, node: AstPtr::new(&node) }); | 668 | sink.push(UnresolvedMacroCall { |
669 | file: ast.file_id, | ||
670 | node: AstPtr::new(&node), | ||
671 | path: path.clone(), | ||
672 | }); | ||
668 | } | 673 | } |
669 | 674 | ||
670 | DiagnosticKind::MacroError { ast, message } => { | 675 | DiagnosticKind::MacroError { ast, message } => { |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index fb4ddff5e..05ceb1efb 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -829,7 +829,7 @@ impl DefCollector<'_> { | |||
829 | res = ReachedFixedPoint::No; | 829 | res = ReachedFixedPoint::No; |
830 | return false; | 830 | return false; |
831 | } | 831 | } |
832 | Err(UnresolvedMacro) | Ok(Err(_)) => {} | 832 | Err(UnresolvedMacro { .. }) | Ok(Err(_)) => {} |
833 | } | 833 | } |
834 | } | 834 | } |
835 | MacroDirectiveKind::Derive { ast_id, derive_attr } => { | 835 | MacroDirectiveKind::Derive { ast_id, derive_attr } => { |
@@ -845,7 +845,7 @@ impl DefCollector<'_> { | |||
845 | res = ReachedFixedPoint::No; | 845 | res = ReachedFixedPoint::No; |
846 | return false; | 846 | return false; |
847 | } | 847 | } |
848 | Err(UnresolvedMacro) => (), | 848 | Err(UnresolvedMacro { .. }) => (), |
849 | } | 849 | } |
850 | } | 850 | } |
851 | } | 851 | } |
@@ -943,10 +943,11 @@ impl DefCollector<'_> { | |||
943 | &mut |_| (), | 943 | &mut |_| (), |
944 | ) { | 944 | ) { |
945 | Ok(_) => (), | 945 | Ok(_) => (), |
946 | Err(UnresolvedMacro) => { | 946 | Err(UnresolvedMacro { path }) => { |
947 | self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call( | 947 | self.def_map.diagnostics.push(DefDiagnostic::unresolved_macro_call( |
948 | directive.module_id, | 948 | directive.module_id, |
949 | ast_id.ast_id, | 949 | ast_id.ast_id, |
950 | path, | ||
950 | )); | 951 | )); |
951 | } | 952 | } |
952 | }, | 953 | }, |
@@ -1530,7 +1531,7 @@ impl ModCollector<'_, '_> { | |||
1530 | )); | 1531 | )); |
1531 | return; | 1532 | return; |
1532 | } | 1533 | } |
1533 | Err(UnresolvedMacro) => (), | 1534 | Err(UnresolvedMacro { .. }) => (), |
1534 | } | 1535 | } |
1535 | 1536 | ||
1536 | // Case 2: resolve in module scope, expand during name resolution. | 1537 | // Case 2: resolve in module scope, expand during name resolution. |
diff --git a/crates/hir_def/src/nameres/tests/diagnostics.rs b/crates/hir_def/src/nameres/tests/diagnostics.rs index 1ac88fc89..543975e07 100644 --- a/crates/hir_def/src/nameres/tests/diagnostics.rs +++ b/crates/hir_def/src/nameres/tests/diagnostics.rs | |||
@@ -170,7 +170,7 @@ fn unresolved_legacy_scope_macro() { | |||
170 | 170 | ||
171 | m!(); | 171 | m!(); |
172 | m2!(); | 172 | m2!(); |
173 | //^^^^^^ unresolved macro call | 173 | //^^^^^^ unresolved macro `self::m2!` |
174 | "#, | 174 | "#, |
175 | ); | 175 | ); |
176 | } | 176 | } |
@@ -187,7 +187,7 @@ fn unresolved_module_scope_macro() { | |||
187 | 187 | ||
188 | self::m!(); | 188 | self::m!(); |
189 | self::m2!(); | 189 | self::m2!(); |
190 | //^^^^^^^^^^^^ unresolved macro call | 190 | //^^^^^^^^^^^^ unresolved macro `self::m2!` |
191 | "#, | 191 | "#, |
192 | ); | 192 | ); |
193 | } | 193 | } |