diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-02 11:30:49 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-02 11:30:49 +0100 |
commit | fb8fb65131c8d3e6335efd401e4e83287be49357 (patch) | |
tree | 9b82278d8f204a012a1e115f92b252c7c6150e15 /crates/ra_hir_def/src/nameres/tests | |
parent | 75bc0249463b72971200e482d69dad88d4e76ae3 (diff) | |
parent | edf0b4c1528407d5077220191e601ac41f790b99 (diff) |
Merge #4234
4234: Support local_inner_macros r=jonas-schievink a=edwin0cheng
This PR implements `#[macro_export(local_inner_macros)]` support.
Note that the rustc implementation is quite [hacky][1] too. :)
[1]: https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres/tests')
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/macros.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs index b0befdfbd..9bc0e6287 100644 --- a/crates/ra_hir_def/src/nameres/tests/macros.rs +++ b/crates/ra_hir_def/src/nameres/tests/macros.rs | |||
@@ -136,6 +136,43 @@ fn macro_rules_export_with_local_inner_macros_are_visible() { | |||
136 | } | 136 | } |
137 | 137 | ||
138 | #[test] | 138 | #[test] |
139 | fn local_inner_macros_makes_local_macros_usable() { | ||
140 | let map = def_map( | ||
141 | " | ||
142 | //- /main.rs crate:main deps:foo | ||
143 | foo::structs!(Foo, Bar); | ||
144 | mod bar; | ||
145 | //- /bar.rs | ||
146 | use crate::*; | ||
147 | //- /lib.rs crate:foo | ||
148 | #[macro_export(local_inner_macros)] | ||
149 | macro_rules! structs { | ||
150 | ($($i:ident),*) => { | ||
151 | inner!($($i),*); | ||
152 | } | ||
153 | } | ||
154 | #[macro_export] | ||
155 | macro_rules! inner { | ||
156 | ($($i:ident),*) => { | ||
157 | $(struct $i { field: u32 } )* | ||
158 | } | ||
159 | } | ||
160 | ", | ||
161 | ); | ||
162 | assert_snapshot!(map, @r###" | ||
163 | ⋮crate | ||
164 | ⋮Bar: t v | ||
165 | ⋮Foo: t v | ||
166 | ⋮bar: t | ||
167 | ⋮ | ||
168 | ⋮crate::bar | ||
169 | ⋮Bar: t v | ||
170 | ⋮Foo: t v | ||
171 | ⋮bar: t | ||
172 | "###); | ||
173 | } | ||
174 | |||
175 | #[test] | ||
139 | fn unexpanded_macro_should_expand_by_fixedpoint_loop() { | 176 | fn unexpanded_macro_should_expand_by_fixedpoint_loop() { |
140 | let map = def_map( | 177 | let map = def_map( |
141 | " | 178 | " |