1828: add macros with local_inner_macros argument r=matklad a=JasperDeSutter

fixes #1816

Co-authored-by: JasperDeSutter <jasper.desutter@gmail.com>
This commit is contained in:
bors[bot] 2019-09-12 13:38:09 +00:00 committed by GitHub
commit 5c09c5949a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View file

@ -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));
}

View file

@ -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(