From 319fcd01ac768c05f24c1d3d306ab68632c8de3e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 2 Dec 2020 14:23:51 +0100 Subject: Attach macro expansion errors to the right file --- crates/hir_def/src/body/lower.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 2c41c0005..689a3274c 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -560,6 +560,9 @@ impl ExprCollector<'_> { // FIXME: do we still need to allocate this as missing ? self.alloc_expr(Expr::Missing, syntax_ptr) } else { + // File containing the macro call. Expansion errors will be attached here. + let outer_file = self.expander.current_file_id; + let macro_call = self.expander.to_source(AstPtr::new(&e)); let res = self.expander.enter_expand(self.db, Some(&self.body.item_scope), e); @@ -567,7 +570,7 @@ impl ExprCollector<'_> { Some(ExpandError::UnresolvedProcMacro) => { self.source_map.diagnostics.push(BodyDiagnostic::UnresolvedProcMacro( UnresolvedProcMacro { - file: self.expander.current_file_id, + file: outer_file, node: syntax_ptr.clone().into(), precise_location: None, macro_name: None, @@ -577,7 +580,7 @@ impl ExprCollector<'_> { Some(err) => { self.source_map.diagnostics.push(BodyDiagnostic::MacroError( MacroError { - file: self.expander.current_file_id, + file: outer_file, node: syntax_ptr.clone().into(), message: err.to_string(), }, -- cgit v1.2.3