From be50908a5031fee45fcbba97bc0c96187324ea54 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 30 Nov 2020 20:26:35 +0100 Subject: Emit macro diagnostics when lowering bodies --- crates/hir_def/src/body/diagnostics.rs | 6 +++++- crates/hir_def/src/body/lower.rs | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'crates/hir_def/src/body') 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 @@ use hir_expand::diagnostics::DiagnosticSink; -use crate::diagnostics::InactiveCode; +use crate::diagnostics::{InactiveCode, MacroError}; #[derive(Debug, Eq, PartialEq)] pub(crate) enum BodyDiagnostic { InactiveCode(InactiveCode), + MacroError(MacroError), } impl BodyDiagnostic { @@ -15,6 +16,9 @@ impl BodyDiagnostic { BodyDiagnostic::InactiveCode(diag) => { sink.push(diag.clone()); } + BodyDiagnostic::MacroError(diag) => { + sink.push(diag.clone()); + } } } } 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::{ body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, builtin_type::{BuiltinFloat, BuiltinInt}, db::DefDatabase, - diagnostics::InactiveCode, + diagnostics::{InactiveCode, MacroError}, expr::{ dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, @@ -561,7 +561,17 @@ impl ExprCollector<'_> { self.alloc_expr(Expr::Missing, syntax_ptr) } else { let macro_call = self.expander.to_source(AstPtr::new(&e)); - match self.expander.enter_expand(self.db, Some(&self.body.item_scope), e) { + let res = self.expander.enter_expand(self.db, Some(&self.body.item_scope), e); + + if let Some(err) = res.err { + self.source_map.diagnostics.push(BodyDiagnostic::MacroError(MacroError { + file: self.expander.current_file_id, + node: syntax_ptr.clone().into(), + message: err.to_string(), + })); + } + + match res.value { Some((mark, expansion)) => { self.source_map .expansions -- cgit v1.2.3