Emit unresolved proc macro errors
This commit is contained in:
parent
be50908a50
commit
ea7b81fef9
@ -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 @@ pub(crate) fn add_to(&self, sink: &mut DiagnosticSink<'_>) {
|
||||
BodyDiagnostic::MacroError(diag) => {
|
||||
sink.push(diag.clone());
|
||||
}
|
||||
BodyDiagnostic::UnresolvedProcMacro(diag) => {
|
||||
sink.push(diag.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
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 @@
|
||||
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 @@ fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user