Skip to content

Commit 3d904e0

Browse files
committed
Auto merge of rust-lang#14286 - Veykril:block-def-tail-mac, r=Veykril
fix: Fix block defmap not looking into tail expressions for macro calls Fixes rust-lang/rust-analyzer#14263
2 parents db64f3a + d038892 commit 3d904e0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

crates/hir-def/src/body/tests/block.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,25 @@ fn foo() {
395395
"#]],
396396
)
397397
}
398+
399+
#[test]
400+
fn trailing_expr_macro_expands_stmts() {
401+
check_at(
402+
r#"
403+
macro_rules! foo {
404+
() => { const FOO: u32 = 0;const BAR: u32 = 0; };
405+
}
406+
fn f() {$0
407+
foo!{}
408+
};
409+
"#,
410+
expect![[r#"
411+
block scope
412+
BAR: v
413+
FOO: v
414+
415+
crate
416+
f: v
417+
"#]],
418+
)
419+
}

crates/hir-def/src/item_tree/lower.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ impl<'a> Ctx<'a> {
9090
_ => None,
9191
})
9292
.collect();
93+
if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr() {
94+
if let Some(call) = expr.macro_call() {
95+
if let Some(mod_item) = self.lower_mod_item(&call.into()) {
96+
self.tree.top_level.push(mod_item);
97+
}
98+
}
99+
}
93100

94101
self.tree
95102
}

0 commit comments

Comments
 (0)