aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-11-30 19:26:35 +0000
committerJonas Schievink <[email protected]>2020-11-30 19:26:35 +0000
commitbe50908a5031fee45fcbba97bc0c96187324ea54 (patch)
tree5999fc43c0d54aaa69dcbf22f693cb29addc31d7 /crates/hir_def/src/body
parent455a0cfda2121596deb13ca3f40a83c98b32863c (diff)
Emit macro diagnostics when lowering bodies
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.rs14
2 files changed, 17 insertions, 3 deletions
diff --git a/crates/hir_def/src/body/diagnostics.rs b/crates/hir_def/src/body/diagnostics.rs
index e57bdc133..144c61b17 100644
--- a/crates/hir_def/src/body/diagnostics.rs
+++ b/crates/hir_def/src/body/diagnostics.rs
@@ -2,11 +2,12 @@
2 2
3use hir_expand::diagnostics::DiagnosticSink; 3use hir_expand::diagnostics::DiagnosticSink;
4 4
5use crate::diagnostics::InactiveCode; 5use crate::diagnostics::{InactiveCode, MacroError};
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} 11}
11 12
12impl BodyDiagnostic { 13impl BodyDiagnostic {
@@ -15,6 +16,9 @@ impl BodyDiagnostic {
15 BodyDiagnostic::InactiveCode(diag) => { 16 BodyDiagnostic::InactiveCode(diag) => {
16 sink.push(diag.clone()); 17 sink.push(diag.clone());
17 } 18 }
19 BodyDiagnostic::MacroError(diag) => {
20 sink.push(diag.clone());
21 }
18 } 22 }
19 } 23 }
20} 24}
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index cd7958746..c0617c1a1 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -25,7 +25,7 @@ use crate::{
25 body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, 25 body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax},
26 builtin_type::{BuiltinFloat, BuiltinInt}, 26 builtin_type::{BuiltinFloat, BuiltinInt},
27 db::DefDatabase, 27 db::DefDatabase,
28 diagnostics::InactiveCode, 28 diagnostics::{InactiveCode, MacroError},
29 expr::{ 29 expr::{
30 dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, 30 dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal,
31 LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, 31 LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
@@ -561,7 +561,17 @@ impl ExprCollector<'_> {
561 self.alloc_expr(Expr::Missing, syntax_ptr) 561 self.alloc_expr(Expr::Missing, syntax_ptr)
562 } else { 562 } else {
563 let macro_call = self.expander.to_source(AstPtr::new(&e)); 563 let macro_call = self.expander.to_source(AstPtr::new(&e));
564 match self.expander.enter_expand(self.db, Some(&self.body.item_scope), e) { 564 let res = self.expander.enter_expand(self.db, Some(&self.body.item_scope), e);
565
566 if let Some(err) = res.err {
567 self.source_map.diagnostics.push(BodyDiagnostic::MacroError(MacroError {
568 file: self.expander.current_file_id,
569 node: syntax_ptr.clone().into(),
570 message: err.to_string(),
571 }));
572 }
573
574 match res.value {
565 Some((mark, expansion)) => { 575 Some((mark, expansion)) => {
566 self.source_map 576 self.source_map
567 .expansions 577 .expansions