From 689e147c9dc416027fd36e94673431533df545f9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 23 Jun 2020 13:46:38 +0200 Subject: Collect inner items in expression macros --- crates/ra_hir_def/src/body/lower.rs | 4 +++- crates/ra_hir_def/src/body/scope.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/body') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index e7cf80676..bbde0b802 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -564,12 +564,14 @@ impl ExprCollector<'_> { }); let tree = &self.item_trees[index].1; + // FIXME: This probably breaks with `use` items, since they produce multiple item tree nodes + // Root file (non-macro). tree.all_inner_items() .chain(tree.top_level_items().iter().copied()) .filter_map(|mod_item| mod_item.downcast::()) .find(|tree_id| tree[*tree_id].ast_id().upcast() == id.value) - .unwrap() + .unwrap_or_else(|| panic!("couldn't find inner item for {:?}", id)) } fn collect_expr_opt(&mut self, expr: Option) -> ExprId { diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 0b74199d9..81397b063 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs @@ -317,6 +317,26 @@ fn foo() { ); } + #[test] + fn macro_inner_item() { + do_check( + r" + macro_rules! mac { + () => {{ + fn inner() {} + inner(); + }}; + } + + fn foo() { + mac!(); + <|> + } + ", + &[], + ); + } + fn do_check_local_name(ra_fixture: &str, expected_offset: u32) { let (db, position) = TestDB::with_position(ra_fixture); let file_id = position.file_id; -- cgit v1.2.3