From ea7b81fef990e281b4b958cff7357544076d4b15 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 1 Dec 2020 12:40:03 +0100 Subject: Emit unresolved proc macro errors --- crates/hir_def/src/body/diagnostics.rs | 6 +++++- crates/hir_def/src/body/lower.rs | 31 +++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body/diagnostics.rs b/crates/hir_def/src/body/diagnostics.rs index 144c61b17..1de7d30e2 100644 --- a/crates/hir_def/src/body/diagnostics.rs +++ b/crates/hir_def/src/body/diagnostics.rs @@ -2,12 +2,13 @@ use hir_expand::diagnostics::DiagnosticSink; -use crate::diagnostics::{InactiveCode, MacroError}; +use crate::diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro}; #[derive(Debug, Eq, PartialEq)] pub(crate) enum BodyDiagnostic { InactiveCode(InactiveCode), MacroError(MacroError), + UnresolvedProcMacro(UnresolvedProcMacro), } impl BodyDiagnostic { @@ -19,6 +20,9 @@ impl BodyDiagnostic { BodyDiagnostic::MacroError(diag) => { sink.push(diag.clone()); } + BodyDiagnostic::UnresolvedProcMacro(diag) => { + sink.push(diag.clone()); + } } } } diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index c0617c1a1..2c41c0005 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -8,7 +8,7 @@ use either::Either; use hir_expand::{ hygiene::Hygiene, name::{name, AsName, Name}, - HirFileId, MacroDefId, MacroDefKind, + ExpandError, HirFileId, MacroDefId, MacroDefKind, }; use rustc_hash::FxHashMap; use syntax::{ @@ -25,7 +25,7 @@ use crate::{ body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, builtin_type::{BuiltinFloat, BuiltinInt}, db::DefDatabase, - diagnostics::{InactiveCode, MacroError}, + diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro}, expr::{ dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, @@ -563,12 +563,27 @@ impl ExprCollector<'_> { let macro_call = self.expander.to_source(AstPtr::new(&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.err { + Some(ExpandError::UnresolvedProcMacro) => { + self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro( + UnresolvedProcMacro { + file: self.expander.current_file_id, + node: syntax_ptr.clone().into(), + precise_location: None, + macro_name: None, + }, + )); + } + Some(err) => { + self.source_map.diagnostics.push(BodyDiagnostic::MacroError( + MacroError { + file: self.expander.current_file_id, + node: syntax_ptr.clone().into(), + message: err.to_string(), + }, + )); + } + None => {} } match res.value { -- cgit v1.2.3