Emit unresolved proc macro errors

This commit is contained in:
Jonas Schievink 2020-12-01 12:40:03 +01:00
parent be50908a50
commit ea7b81fef9
2 changed files with 28 additions and 9 deletions

View File

@ -2,12 +2,13 @@
use hir_expand::diagnostics::DiagnosticSink; use hir_expand::diagnostics::DiagnosticSink;
use crate::diagnostics::{InactiveCode, MacroError}; use crate::diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro};
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub(crate) enum BodyDiagnostic { pub(crate) enum BodyDiagnostic {
InactiveCode(InactiveCode), InactiveCode(InactiveCode),
MacroError(MacroError), MacroError(MacroError),
UnresolvedProcMacro(UnresolvedProcMacro),
} }
impl BodyDiagnostic { impl BodyDiagnostic {
@ -19,6 +20,9 @@ pub(crate) fn add_to(&self, sink: &mut DiagnosticSink<'_>) {
BodyDiagnostic::MacroError(diag) => { BodyDiagnostic::MacroError(diag) => {
sink.push(diag.clone()); sink.push(diag.clone());
} }
BodyDiagnostic::UnresolvedProcMacro(diag) => {
sink.push(diag.clone());
}
} }
} }
} }

View File

@ -8,7 +8,7 @@
use hir_expand::{ use hir_expand::{
hygiene::Hygiene, hygiene::Hygiene,
name::{name, AsName, Name}, name::{name, AsName, Name},
HirFileId, MacroDefId, MacroDefKind, ExpandError, HirFileId, MacroDefId, MacroDefKind,
}; };
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use syntax::{ use syntax::{
@ -25,7 +25,7 @@
body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax},
builtin_type::{BuiltinFloat, BuiltinInt}, builtin_type::{BuiltinFloat, BuiltinInt},
db::DefDatabase, db::DefDatabase,
diagnostics::{InactiveCode, MacroError}, diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro},
expr::{ expr::{
dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal, dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal,
LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement, LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
@ -563,12 +563,27 @@ fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
let macro_call = self.expander.to_source(AstPtr::new(&e)); let macro_call = self.expander.to_source(AstPtr::new(&e));
let res = 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 { match res.err {
self.source_map.diagnostics.push(BodyDiagnostic::MacroError(MacroError { Some(ExpandError::UnresolvedProcMacro) => {
file: self.expander.current_file_id, self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro(
node: syntax_ptr.clone().into(), UnresolvedProcMacro {
message: err.to_string(), 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 { match res.value {