Skip to content

Commit 319fcd0

Browse files
Attach macro expansion errors to the right file
1 parent bb69772 commit 319fcd0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

crates/hir_def/src/body/lower.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,17 @@ impl ExprCollector<'_> {
560560
// FIXME: do we still need to allocate this as missing ?
561561
self.alloc_expr(Expr::Missing, syntax_ptr)
562562
} else {
563+
// File containing the macro call. Expansion errors will be attached here.
564+
let outer_file = self.expander.current_file_id;
565+
563566
let macro_call = self.expander.to_source(AstPtr::new(&e));
564567
let res = self.expander.enter_expand(self.db, Some(&self.body.item_scope), e);
565568

566569
match res.err {
567570
Some(ExpandError::UnresolvedProcMacro) => {
568571
self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro(
569572
UnresolvedProcMacro {
570-
file: self.expander.current_file_id,
573+
file: outer_file,
571574
node: syntax_ptr.clone().into(),
572575
precise_location: None,
573576
macro_name: None,
@@ -577,7 +580,7 @@ impl ExprCollector<'_> {
577580
Some(err) => {
578581
self.source_map.diagnostics.push(BodyDiagnostic::MacroError(
579582
MacroError {
580-
file: self.expander.current_file_id,
583+
file: outer_file,
581584
node: syntax_ptr.clone().into(),
582585
message: err.to_string(),
583586
},

0 commit comments

Comments
 (0)