aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/nameres/tests.rs17
-rw-r--r--crates/ra_hir/src/nameres/tests/macros.rs40
2 files changed, 55 insertions, 2 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index 14c8ee50b..ffb627c02 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -7,6 +7,7 @@ use std::sync::Arc;
7use ra_db::SourceDatabase; 7use ra_db::SourceDatabase;
8use test_utils::covers; 8use test_utils::covers;
9use insta::assert_snapshot_matches; 9use insta::assert_snapshot_matches;
10use either::Either;
10 11
11use crate::{ 12use crate::{
12 Crate, 13 Crate,
@@ -35,10 +36,22 @@ fn render_crate_def_map(map: &CrateDefMap) -> String {
35 *buf += path; 36 *buf += path;
36 *buf += "\n"; 37 *buf += "\n";
37 38
38 let mut entries = map.modules[module].scope.items.iter().collect::<Vec<_>>(); 39 let items =
40 map.modules[module].scope.items.iter().map(|(name, it)| (name, Either::Left(it)));
41 let macros =
42 map.modules[module].scope.macros.iter().map(|(name, m)| (name, Either::Right(m)));
43 let mut entries = items.chain(macros).collect::<Vec<_>>();
44
39 entries.sort_by_key(|(name, _)| *name); 45 entries.sort_by_key(|(name, _)| *name);
40 for (name, res) in entries { 46 for (name, res) in entries {
41 *buf += &format!("{}: {}\n", name, dump_resolution(res)) 47 match res {
48 Either::Left(it) => {
49 *buf += &format!("{}: {}\n", name, dump_resolution(it));
50 }
51 Either::Right(_) => {
52 *buf += &format!("{}: m\n", name);
53 }
54 }
42 } 55 }
43 for (name, child) in map.modules[module].children.iter() { 56 for (name, child) in map.modules[module].children.iter() {
44 let path = path.to_string() + &format!("::{}", name); 57 let path = path.to_string() + &format!("::{}", name);
diff --git a/crates/ra_hir/src/nameres/tests/macros.rs b/crates/ra_hir/src/nameres/tests/macros.rs
index f7ca380ad..42241aeff 100644
--- a/crates/ra_hir/src/nameres/tests/macros.rs
+++ b/crates/ra_hir/src/nameres/tests/macros.rs
@@ -92,3 +92,43 @@ fn macro_rules_from_other_crates_are_visible() {
92 ⋮bar: t 92 ⋮bar: t
93 "###); 93 "###);
94} 94}
95
96#[test]
97fn unexpanded_macro_should_expand_by_fixedpoint_loop() {
98 let map = def_map_with_crate_graph(
99 "
100 //- /main.rs
101 macro_rules! baz {
102 () => {
103 use foo::bar;
104 }
105 }
106
107 foo!();
108 bar!();
109 baz!();
110
111 //- /lib.rs
112 #[macro_export]
113 macro_rules! foo {
114 () => {
115 struct Foo { field: u32 }
116 }
117 }
118 #[macro_export]
119 macro_rules! bar {
120 () => {
121 use foo::foo;
122 }
123 }
124 ",
125 crate_graph! {
126 "main": ("/main.rs", ["foo"]),
127 "foo": ("/lib.rs", []),
128 },
129 );
130 assert_snapshot_matches!(map, @r###"crate
131Foo: t v
132bar: m
133foo: m"###);
134}