mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-16 07:03:57 +00:00
Merge #1828
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:
commit
5c09c5949a
2 changed files with 40 additions and 1 deletions
|
@ -345,7 +345,9 @@ impl RawItemsCollector {
|
||||||
|
|
||||||
let name = m.name().map(|it| it.as_name());
|
let name = m.name().map(|it| it.as_name());
|
||||||
let ast_id = self.source_ast_id_map.ast_id(&m);
|
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 });
|
let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export });
|
||||||
self.push_item(current_module, RawItem::Macro(m));
|
self.push_item(current_module, RawItem::Macro(m));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
|
fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
|
||||||
let map = def_map_with_crate_graph(
|
let map = def_map_with_crate_graph(
|
||||||
|
|
Loading…
Reference in a new issue