diff options
| author | bors <bors@rust-lang.org> | 2023-03-08 13:37:47 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-08 13:37:47 +0000 |
| commit | 3d904e024b25211d55ca41f8d7faa8f966d124b8 (patch) | |
| tree | 6cc320e4ce0c99e796e8fcf5e4111226104392b4 | |
| parent | db64f3aa695363a5f0ad812bd8fa58e2a911a377 (diff) | |
| parent | d038892947ce3d587523c4a4b1c6bf7f0f2163dc (diff) | |
| download | rust-3d904e024b25211d55ca41f8d7faa8f966d124b8.tar.gz rust-3d904e024b25211d55ca41f8d7faa8f966d124b8.zip | |
Auto merge of #14286 - Veykril:block-def-tail-mac, r=Veykril
fix: Fix block defmap not looking into tail expressions for macro calls Fixes https://github.com/rust-lang/rust-analyzer/issues/14263
| -rw-r--r-- | crates/hir-def/src/body/tests/block.rs | 22 | ||||
| -rw-r--r-- | crates/hir-def/src/item_tree/lower.rs | 7 |
2 files changed, 29 insertions, 0 deletions
diff --git a/crates/hir-def/src/body/tests/block.rs b/crates/hir-def/src/body/tests/block.rs index 3bba08cfcce..77ac221e590 100644 --- a/crates/hir-def/src/body/tests/block.rs +++ b/crates/hir-def/src/body/tests/block.rs @@ -395,3 +395,25 @@ fn foo() { "#]], ) } + +#[test] +fn trailing_expr_macro_expands_stmts() { + check_at( + r#" +macro_rules! foo { + () => { const FOO: u32 = 0;const BAR: u32 = 0; }; +} +fn f() {$0 + foo!{} +}; + "#, + expect![[r#" + block scope + BAR: v + FOO: v + + crate + f: v + "#]], + ) +} diff --git a/crates/hir-def/src/item_tree/lower.rs b/crates/hir-def/src/item_tree/lower.rs index 495a8878c33..77b186f8e3f 100644 --- a/crates/hir-def/src/item_tree/lower.rs +++ b/crates/hir-def/src/item_tree/lower.rs @@ -90,6 +90,13 @@ impl<'a> Ctx<'a> { _ => None, }) .collect(); + if let Some(ast::Expr::MacroExpr(expr)) = block.tail_expr() { + if let Some(call) = expr.macro_call() { + if let Some(mod_item) = self.lower_mod_item(&call.into()) { + self.tree.top_level.push(mod_item); + } + } + } self.tree } |
