Skip to content

Commit ea7b81f

Browse files
Emit unresolved proc macro errors
1 parent be50908 commit ea7b81f

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

crates/hir_def/src/body/diagnostics.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
33
use hir_expand::diagnostics::DiagnosticSink;
44

5-
use crate::diagnostics::{InactiveCode, MacroError};
5+
use crate::diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro};
66

77
#[derive(Debug, Eq, PartialEq)]
88
pub(crate) enum BodyDiagnostic {
99
InactiveCode(InactiveCode),
1010
MacroError(MacroError),
11+
UnresolvedProcMacro(UnresolvedProcMacro),
1112
}
1213

1314
impl BodyDiagnostic {
@@ -19,6 +20,9 @@ impl BodyDiagnostic {
1920
BodyDiagnostic::MacroError(diag) => {
2021
sink.push(diag.clone());
2122
}
23+
BodyDiagnostic::UnresolvedProcMacro(diag) => {
24+
sink.push(diag.clone());
25+
}
2226
}
2327
}
2428
}

crates/hir_def/src/body/lower.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use either::Either;
88
use hir_expand::{
99
hygiene::Hygiene,
1010
name::{name, AsName, Name},
11-
HirFileId, MacroDefId, MacroDefKind,
11+
ExpandError, HirFileId, MacroDefId, MacroDefKind,
1212
};
1313
use rustc_hash::FxHashMap;
1414
use syntax::{
@@ -25,7 +25,7 @@ use crate::{
2525
body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax},
2626
builtin_type::{BuiltinFloat, BuiltinInt},
2727
db::DefDatabase,
28-
diagnostics::{InactiveCode, MacroError},
28+
diagnostics::{InactiveCode, MacroError, UnresolvedProcMacro},
2929
expr::{
3030
dummy_expr_id, ArithOp, Array, BinaryOp, BindingAnnotation, CmpOp, Expr, ExprId, Literal,
3131
LogicOp, MatchArm, Ordering, Pat, PatId, RecordFieldPat, RecordLitField, Statement,
@@ -563,12 +563,27 @@ impl ExprCollector<'_> {
563563
let macro_call = self.expander.to_source(AstPtr::new(&e));
564564
let res = self.expander.enter_expand(self.db, Some(&self.body.item_scope), e);
565565

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-
}));
566+
match res.err {
567+
Some(ExpandError::UnresolvedProcMacro) => {
568+
self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro(
569+
UnresolvedProcMacro {
570+
file: self.expander.current_file_id,
571+
node: syntax_ptr.clone().into(),
572+
precise_location: None,
573+
macro_name: None,
574+
},
575+
));
576+
}
577+
Some(err) => {
578+
self.source_map.diagnostics.push(BodyDiagnostic::MacroError(
579+
MacroError {
580+
file: self.expander.current_file_id,
581+
node: syntax_ptr.clone().into(),
582+
message: err.to_string(),
583+
},
584+
));
585+
}
586+
None => {}
572587
}
573588

574589
match res.value {

0 commit comments

Comments
 (0)