aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/body')
-rw-r--r--crates/hir_def/src/body/diagnostics.rs6
-rw-r--r--crates/hir_def/src/body/lower.rs15
-rw-r--r--crates/hir_def/src/body/tests.rs12
3 files changed, 30 insertions, 3 deletions
diff --git a/crates/hir_def/src/body/diagnostics.rs b/crates/hir_def/src/body/diagnostics.rs
index 1de7d30e2..f6992c9a8 100644
--- a/crates/hir_def/src/body/diagnostics.rs
+++ b/crates/hir_def/src/body/diagnostics.rs
@@ -2,13 +2,14 @@
2 2
3use hir_expand::diagnostics::DiagnosticSink; 3use hir_expand::diagnostics::DiagnosticSink;
4 4
5use crate::diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro}; 5use crate::diagnostics::{InactiveCode, MacroError, UnresolvedMacroCall, UnresolvedProcMacro};
6 6
7#[derive(Debug, Eq, PartialEq)] 7#[derive(Debug, Eq, PartialEq)]
8pub(crate) enum BodyDiagnostic { 8pub(crate) enum BodyDiagnostic {
9 InactiveCode(InactiveCode), 9 InactiveCode(InactiveCode),
10 MacroError(MacroError), 10 MacroError(MacroError),
11 UnresolvedProcMacro(UnresolvedProcMacro), 11 UnresolvedProcMacro(UnresolvedProcMacro),
12 UnresolvedMacroCall(UnresolvedMacroCall),
12} 13}
13 14
14impl BodyDiagnostic { 15impl BodyDiagnostic {
@@ -23,6 +24,9 @@ impl BodyDiagnostic {
23 BodyDiagnostic::UnresolvedProcMacro(diag) => { 24 BodyDiagnostic::UnresolvedProcMacro(diag) => {
24 sink.push(diag.clone()); 25 sink.push(diag.clone());
25 } 26 }
27 BodyDiagnostic::UnresolvedMacroCall(diag) => {
28 sink.push(diag.clone());
29 }
26 } 30 }
27 } 31 }
28} 32}
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 7052058f2..60b25db56 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -24,7 +24,7 @@ use crate::{
24 body::{Body, BodySourceMap, Expander, LabelSource, PatPtr, SyntheticSyntax}, 24 body::{Body, BodySourceMap, Expander, LabelSource, PatPtr, SyntheticSyntax},
25 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint}, 25 builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
26 db::DefDatabase, 26 db::DefDatabase,
27 diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro}, 27 diagnostics::{InactiveCode, MacroError, UnresolvedMacroCall, UnresolvedProcMacro},
28 expr::{ 28 expr::{
29 dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Label, 29 dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Label,
30 LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, 30 LabelId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField,
@@ -33,7 +33,7 @@ use crate::{
33 item_scope::BuiltinShadowMode, 33 item_scope::BuiltinShadowMode,
34 path::{GenericArgs, Path}, 34 path::{GenericArgs, Path},
35 type_ref::{Mutability, Rawness, TypeRef}, 35 type_ref::{Mutability, Rawness, TypeRef},
36 AdtId, BlockLoc, ModuleDefId, 36 AdtId, BlockLoc, ModuleDefId, UnresolvedMacro,
37}; 37};
38 38
39use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource}; 39use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource};
@@ -554,6 +554,17 @@ impl ExprCollector<'_> {
554 let macro_call = self.expander.to_source(AstPtr::new(&e)); 554 let macro_call = self.expander.to_source(AstPtr::new(&e));
555 let res = self.expander.enter_expand(self.db, e); 555 let res = self.expander.enter_expand(self.db, e);
556 556
557 let res = match res {
558 Ok(res) => res,
559 Err(UnresolvedMacro) => {
560 self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedMacroCall(
561 UnresolvedMacroCall { file: outer_file, node: syntax_ptr.cast().unwrap() },
562 ));
563 collector(self, None);
564 return;
565 }
566 };
567
557 match &res.err { 568 match &res.err {
558 Some(ExpandError::UnresolvedProcMacro) => { 569 Some(ExpandError::UnresolvedProcMacro) => {
559 self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro( 570 self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro(
diff --git a/crates/hir_def/src/body/tests.rs b/crates/hir_def/src/body/tests.rs
index 991a32b15..f8e6f70e8 100644
--- a/crates/hir_def/src/body/tests.rs
+++ b/crates/hir_def/src/body/tests.rs
@@ -175,6 +175,18 @@ fn f() {
175} 175}
176 176
177#[test] 177#[test]
178fn unresolved_macro_diag() {
179 check_diagnostics(
180 r#"
181fn f() {
182 m!();
183 //^^^^ unresolved macro call
184}
185 "#,
186 );
187}
188
189#[test]
178fn dollar_crate_in_builtin_macro() { 190fn dollar_crate_in_builtin_macro() {
179 check_diagnostics( 191 check_diagnostics(
180 r#" 192 r#"