From e6ee324b8529df86f330f5240cbb7bb9048fff57 Mon Sep 17 00:00:00 2001 From: JasperDeSutter Date: Thu, 12 Sep 2019 14:41:16 +0200 Subject: add macros with local_inner_macros argument --- crates/ra_hir/src/nameres/raw.rs | 4 +++- crates/ra_hir/src/nameres/tests/macros.rs | 37 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs index 04b97cb90..8bf883ac2 100644 --- a/crates/ra_hir/src/nameres/raw.rs +++ b/crates/ra_hir/src/nameres/raw.rs @@ -345,7 +345,9 @@ impl RawItemsCollector { let name = m.name().map(|it| it.as_name()); let ast_id = self.source_ast_id_map.ast_id(&m); - let export = m.has_atom_attr("macro_export"); + let export = m.has_atom_attr("macro_export") + || m.attrs().filter_map(|x| x.as_call()).any(|(name, _)| name == "macro_export"); + let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export }); self.push_item(current_module, RawItem::Macro(m)); } diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs index 6e0bc437e..bd60f4258 100644 --- a/crates/ra_hir/src/nameres/tests/macros.rs +++ b/crates/ra_hir/src/nameres/tests/macros.rs @@ -93,6 +93,43 @@ fn macro_rules_from_other_crates_are_visible() { "###); } +#[test] +fn macro_rules_export_with_local_inner_macros_are_visible() { + let map = def_map_with_crate_graph( + " + //- /main.rs + foo::structs!(Foo, Bar) + mod bar; + + //- /bar.rs + use crate::*; + + //- /lib.rs + #[macro_export(local_inner_macros)] + macro_rules! structs { + ($($i:ident),*) => { + $(struct $i { field: u32 } )* + } + } + ", + crate_graph! { + "main": ("/main.rs", ["foo"]), + "foo": ("/lib.rs", []), + }, + ); + assert_snapshot!(map, @r###" + ⋮crate + ⋮Bar: t v + ⋮Foo: t v + ⋮bar: t + ⋮ + ⋮crate::bar + ⋮Bar: t v + ⋮Foo: t v + ⋮bar: t + "###); +} + #[test] fn unexpanded_macro_should_expand_by_fixedpoint_loop() { let map = def_map_with_crate_graph( -- cgit v1.2.3