diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-27 08:38:21 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-27 08:38:21 +0100 |
commit | bdd779aa44455d86a9975800ab6cd70057fab4a3 (patch) | |
tree | 6c39bd0ad6ce7ab52cfcf19ad6b5c8f34c68420f /crates/ra_hir/src/nameres/tests | |
parent | ce694ae11854a806031db98c51c068253f927519 (diff) | |
parent | 6d68d60d32222af9fda1a6a89911a2c25f4fe402 (diff) |
Merge #1277
1277: Improve macro item resolution r=matklad a=edwin0cheng
~This PR add a new namespace `Macros` in `per_ns.rs` to allow following use case:~
This PR improve macro item resolution to allow following use case:
```rust
//- /main.rs
use foo::bar;
bar!();
//- /lib.rs (crate foo)
#[macro_export]
macro_rules! bar{
() => {
struct Foo { field: u32 }
}
```
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres/tests')
-rw-r--r-- | crates/ra_hir/src/nameres/tests/macros.rs | 40 |
1 files changed, 40 insertions, 0 deletions
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] | ||
97 | fn 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 | ||
131 | Foo: t v | ||
132 | bar: m | ||
133 | foo: m"###); | ||
134 | } | ||