Skip to content

Commit 3e1fb11

Browse files
Merge #6698
6698: Attach macro expansion errors to the right file r=jonas-schievink a=jonas-schievink Previously it attached them to the result of the macro expansion (or, if no result was produced, to the file containing the invocation). Always use the file containing the invocation. This doesn't seem to have any observable difference, but seems better in theory. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents dc09d97 + 319fcd0 commit 3e1fb11

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)