diff options
Diffstat (limited to 'crates/ra_hir_def/src/nameres/tests/macros.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/macros.rs | 1061 |
1 files changed, 534 insertions, 527 deletions
diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs index 84480d9f6..e0fb8bdef 100644 --- a/crates/ra_hir_def/src/nameres/tests/macros.rs +++ b/crates/ra_hir_def/src/nameres/tests/macros.rs | |||
@@ -2,639 +2,631 @@ use super::*; | |||
2 | 2 | ||
3 | #[test] | 3 | #[test] |
4 | fn macro_rules_are_globally_visible() { | 4 | fn macro_rules_are_globally_visible() { |
5 | let map = def_map( | 5 | check( |
6 | r" | 6 | r#" |
7 | //- /lib.rs | 7 | //- /lib.rs |
8 | macro_rules! structs { | 8 | macro_rules! structs { |
9 | ($($i:ident),*) => { | 9 | ($($i:ident),*) => { |
10 | $(struct $i { field: u32 } )* | 10 | $(struct $i { field: u32 } )* |
11 | } | 11 | } |
12 | } | 12 | } |
13 | structs!(Foo); | 13 | structs!(Foo); |
14 | mod nested; | 14 | mod nested; |
15 | 15 | ||
16 | //- /nested.rs | 16 | //- /nested.rs |
17 | structs!(Bar, Baz); | 17 | structs!(Bar, Baz); |
18 | ", | 18 | "#, |
19 | expect![[r#" | ||
20 | crate | ||
21 | Foo: t | ||
22 | nested: t | ||
23 | |||
24 | crate::nested | ||
25 | Bar: t | ||
26 | Baz: t | ||
27 | "#]], | ||
19 | ); | 28 | ); |
20 | assert_snapshot!(map, @r###" | ||
21 | ⋮crate | ||
22 | ⋮Foo: t | ||
23 | ⋮nested: t | ||
24 | ⋮ | ||
25 | ⋮crate::nested | ||
26 | ⋮Bar: t | ||
27 | ⋮Baz: t | ||
28 | "###); | ||
29 | } | 29 | } |
30 | 30 | ||
31 | #[test] | 31 | #[test] |
32 | fn macro_rules_can_define_modules() { | 32 | fn macro_rules_can_define_modules() { |
33 | let map = def_map( | 33 | check( |
34 | r" | 34 | r#" |
35 | //- /lib.rs | 35 | //- /lib.rs |
36 | macro_rules! m { | 36 | macro_rules! m { |
37 | ($name:ident) => { mod $name; } | 37 | ($name:ident) => { mod $name; } |
38 | } | 38 | } |
39 | m!(n1); | 39 | m!(n1); |
40 | 40 | mod m { m!(n3) } | |
41 | mod m { | 41 | |
42 | m!(n3) | 42 | //- /n1.rs |
43 | } | 43 | m!(n2) |
44 | 44 | //- /n1/n2.rs | |
45 | //- /n1.rs | 45 | struct X; |
46 | m!(n2) | 46 | //- /m/n3.rs |
47 | //- /n1/n2.rs | 47 | struct Y; |
48 | struct X; | 48 | "#, |
49 | //- /m/n3.rs | 49 | expect![[r#" |
50 | struct Y; | 50 | crate |
51 | ", | 51 | m: t |
52 | n1: t | ||
53 | |||
54 | crate::m | ||
55 | n3: t | ||
56 | |||
57 | crate::m::n3 | ||
58 | Y: t v | ||
59 | |||
60 | crate::n1 | ||
61 | n2: t | ||
62 | |||
63 | crate::n1::n2 | ||
64 | X: t v | ||
65 | "#]], | ||
52 | ); | 66 | ); |
53 | assert_snapshot!(map, @r###" | ||
54 | ⋮crate | ||
55 | ⋮m: t | ||
56 | ⋮n1: t | ||
57 | ⋮ | ||
58 | ⋮crate::m | ||
59 | ⋮n3: t | ||
60 | ⋮ | ||
61 | ⋮crate::m::n3 | ||
62 | ⋮Y: t v | ||
63 | ⋮ | ||
64 | ⋮crate::n1 | ||
65 | ⋮n2: t | ||
66 | ⋮ | ||
67 | ⋮crate::n1::n2 | ||
68 | ⋮X: t v | ||
69 | "###); | ||
70 | } | 67 | } |
71 | 68 | ||
72 | #[test] | 69 | #[test] |
73 | fn macro_rules_from_other_crates_are_visible() { | 70 | fn macro_rules_from_other_crates_are_visible() { |
74 | let map = def_map( | 71 | check( |
75 | " | 72 | r#" |
76 | //- /main.rs crate:main deps:foo | 73 | //- /main.rs crate:main deps:foo |
77 | foo::structs!(Foo, Bar) | 74 | foo::structs!(Foo, Bar) |
78 | mod bar; | 75 | mod bar; |
79 | 76 | ||
80 | //- /bar.rs | 77 | //- /bar.rs |
81 | use crate::*; | 78 | use crate::*; |
82 | 79 | ||
83 | //- /lib.rs crate:foo | 80 | //- /lib.rs crate:foo |
84 | #[macro_export] | 81 | #[macro_export] |
85 | macro_rules! structs { | 82 | macro_rules! structs { |
86 | ($($i:ident),*) => { | 83 | ($($i:ident),*) => { |
87 | $(struct $i { field: u32 } )* | 84 | $(struct $i { field: u32 } )* |
88 | } | 85 | } |
89 | } | 86 | } |
90 | ", | 87 | "#, |
88 | expect![[r#" | ||
89 | crate | ||
90 | Bar: t | ||
91 | Foo: t | ||
92 | bar: t | ||
93 | |||
94 | crate::bar | ||
95 | Bar: t | ||
96 | Foo: t | ||
97 | bar: t | ||
98 | "#]], | ||
91 | ); | 99 | ); |
92 | assert_snapshot!(map, @r###" | ||
93 | ⋮crate | ||
94 | ⋮Bar: t | ||
95 | ⋮Foo: t | ||
96 | ⋮bar: t | ||
97 | ⋮ | ||
98 | ⋮crate::bar | ||
99 | ⋮Bar: t | ||
100 | ⋮Foo: t | ||
101 | ⋮bar: t | ||
102 | "###); | ||
103 | } | 100 | } |
104 | 101 | ||
105 | #[test] | 102 | #[test] |
106 | fn macro_rules_export_with_local_inner_macros_are_visible() { | 103 | fn macro_rules_export_with_local_inner_macros_are_visible() { |
107 | let map = def_map( | 104 | check( |
108 | " | 105 | r#" |
109 | //- /main.rs crate:main deps:foo | 106 | //- /main.rs crate:main deps:foo |
110 | foo::structs!(Foo, Bar) | 107 | foo::structs!(Foo, Bar) |
111 | mod bar; | 108 | mod bar; |
112 | 109 | ||
113 | //- /bar.rs | 110 | //- /bar.rs |
114 | use crate::*; | 111 | use crate::*; |
115 | 112 | ||
116 | //- /lib.rs crate:foo | 113 | //- /lib.rs crate:foo |
117 | #[macro_export(local_inner_macros)] | 114 | #[macro_export(local_inner_macros)] |
118 | macro_rules! structs { | 115 | macro_rules! structs { |
119 | ($($i:ident),*) => { | 116 | ($($i:ident),*) => { |
120 | $(struct $i { field: u32 } )* | 117 | $(struct $i { field: u32 } )* |
121 | } | 118 | } |
122 | } | 119 | } |
123 | ", | 120 | "#, |
121 | expect![[r#" | ||
122 | crate | ||
123 | Bar: t | ||
124 | Foo: t | ||
125 | bar: t | ||
126 | |||
127 | crate::bar | ||
128 | Bar: t | ||
129 | Foo: t | ||
130 | bar: t | ||
131 | "#]], | ||
124 | ); | 132 | ); |
125 | assert_snapshot!(map, @r###" | ||
126 | ⋮crate | ||
127 | ⋮Bar: t | ||
128 | ⋮Foo: t | ||
129 | ⋮bar: t | ||
130 | ⋮ | ||
131 | ⋮crate::bar | ||
132 | ⋮Bar: t | ||
133 | ⋮Foo: t | ||
134 | ⋮bar: t | ||
135 | "###); | ||
136 | } | 133 | } |
137 | 134 | ||
138 | #[test] | 135 | #[test] |
139 | fn local_inner_macros_makes_local_macros_usable() { | 136 | fn local_inner_macros_makes_local_macros_usable() { |
140 | let map = def_map( | 137 | check( |
141 | " | 138 | r#" |
142 | //- /main.rs crate:main deps:foo | 139 | //- /main.rs crate:main deps:foo |
143 | foo::structs!(Foo, Bar); | 140 | foo::structs!(Foo, Bar); |
144 | mod bar; | 141 | mod bar; |
145 | //- /bar.rs | 142 | |
146 | use crate::*; | 143 | //- /bar.rs |
147 | //- /lib.rs crate:foo | 144 | use crate::*; |
148 | #[macro_export(local_inner_macros)] | 145 | |
149 | macro_rules! structs { | 146 | //- /lib.rs crate:foo |
150 | ($($i:ident),*) => { | 147 | #[macro_export(local_inner_macros)] |
151 | inner!($($i),*); | 148 | macro_rules! structs { |
152 | } | 149 | ($($i:ident),*) => { |
153 | } | 150 | inner!($($i),*); |
154 | #[macro_export] | 151 | } |
155 | macro_rules! inner { | 152 | } |
156 | ($($i:ident),*) => { | 153 | #[macro_export] |
157 | $(struct $i { field: u32 } )* | 154 | macro_rules! inner { |
158 | } | 155 | ($($i:ident),*) => { |
159 | } | 156 | $(struct $i { field: u32 } )* |
160 | ", | 157 | } |
158 | } | ||
159 | "#, | ||
160 | expect![[r#" | ||
161 | crate | ||
162 | Bar: t | ||
163 | Foo: t | ||
164 | bar: t | ||
165 | |||
166 | crate::bar | ||
167 | Bar: t | ||
168 | Foo: t | ||
169 | bar: t | ||
170 | "#]], | ||
161 | ); | 171 | ); |
162 | assert_snapshot!(map, @r###" | ||
163 | ⋮crate | ||
164 | ⋮Bar: t | ||
165 | ⋮Foo: t | ||
166 | ⋮bar: t | ||
167 | ⋮ | ||
168 | ⋮crate::bar | ||
169 | ⋮Bar: t | ||
170 | ⋮Foo: t | ||
171 | ⋮bar: t | ||
172 | "###); | ||
173 | } | 172 | } |
174 | 173 | ||
175 | #[test] | 174 | #[test] |
176 | fn unexpanded_macro_should_expand_by_fixedpoint_loop() { | 175 | fn unexpanded_macro_should_expand_by_fixedpoint_loop() { |
177 | let map = def_map( | 176 | check( |
178 | " | 177 | r#" |
179 | //- /main.rs crate:main deps:foo | 178 | //- /main.rs crate:main deps:foo |
180 | macro_rules! baz { | 179 | macro_rules! baz { |
181 | () => { | 180 | () => { |
182 | use foo::bar; | 181 | use foo::bar; |
183 | } | 182 | } |
184 | } | 183 | } |
185 | 184 | foo!(); | |
186 | foo!(); | 185 | bar!(); |
187 | bar!(); | 186 | baz!(); |
188 | baz!(); | 187 | |
189 | 188 | //- /lib.rs crate:foo | |
190 | //- /lib.rs crate:foo | 189 | #[macro_export] |
191 | #[macro_export] | 190 | macro_rules! foo { |
192 | macro_rules! foo { | 191 | () => { |
193 | () => { | 192 | struct Foo { field: u32 } |
194 | struct Foo { field: u32 } | 193 | } |
195 | } | 194 | } |
196 | } | 195 | #[macro_export] |
197 | #[macro_export] | 196 | macro_rules! bar { |
198 | macro_rules! bar { | 197 | () => { |
199 | () => { | 198 | use foo::foo; |
200 | use foo::foo; | 199 | } |
201 | } | 200 | } |
202 | } | 201 | "#, |
203 | ", | 202 | expect![[r#" |
203 | crate | ||
204 | Foo: t | ||
205 | bar: m | ||
206 | foo: m | ||
207 | "#]], | ||
204 | ); | 208 | ); |
205 | assert_snapshot!(map, @r###" | ||
206 | ⋮crate | ||
207 | ⋮Foo: t | ||
208 | ⋮bar: m | ||
209 | ⋮foo: m | ||
210 | "###); | ||
211 | } | 209 | } |
212 | 210 | ||
213 | #[test] | 211 | #[test] |
214 | fn macro_rules_from_other_crates_are_visible_with_macro_use() { | 212 | fn macro_rules_from_other_crates_are_visible_with_macro_use() { |
215 | mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use); | 213 | mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use); |
216 | let map = def_map( | 214 | check( |
217 | " | 215 | r#" |
218 | //- /main.rs crate:main deps:foo | 216 | //- /main.rs crate:main deps:foo |
219 | structs!(Foo); | 217 | structs!(Foo); |
220 | structs_priv!(Bar); | 218 | structs_priv!(Bar); |
221 | structs_not_exported!(MacroNotResolved1); | 219 | structs_not_exported!(MacroNotResolved1); |
222 | crate::structs!(MacroNotResolved2); | 220 | crate::structs!(MacroNotResolved2); |
223 | 221 | ||
224 | mod bar; | 222 | mod bar; |
225 | 223 | ||
226 | #[macro_use] | 224 | #[macro_use] |
227 | extern crate foo; | 225 | extern crate foo; |
228 | 226 | ||
229 | //- /bar.rs | 227 | //- /bar.rs |
230 | structs!(Baz); | 228 | structs!(Baz); |
231 | crate::structs!(MacroNotResolved3); | 229 | crate::structs!(MacroNotResolved3); |
232 | 230 | ||
233 | //- /lib.rs crate:foo | 231 | //- /lib.rs crate:foo |
234 | #[macro_export] | 232 | #[macro_export] |
235 | macro_rules! structs { | 233 | macro_rules! structs { |
236 | ($i:ident) => { struct $i; } | 234 | ($i:ident) => { struct $i; } |
237 | } | 235 | } |
238 | 236 | ||
239 | macro_rules! structs_not_exported { | 237 | macro_rules! structs_not_exported { |
240 | ($i:ident) => { struct $i; } | 238 | ($i:ident) => { struct $i; } |
241 | } | 239 | } |
242 | 240 | ||
243 | mod priv_mod { | 241 | mod priv_mod { |
244 | #[macro_export] | 242 | #[macro_export] |
245 | macro_rules! structs_priv { | 243 | macro_rules! structs_priv { |
246 | ($i:ident) => { struct $i; } | 244 | ($i:ident) => { struct $i; } |
247 | } | 245 | } |
248 | } | 246 | } |
249 | ", | 247 | "#, |
248 | expect![[r#" | ||
249 | crate | ||
250 | Bar: t v | ||
251 | Foo: t v | ||
252 | bar: t | ||
253 | foo: t | ||
254 | |||
255 | crate::bar | ||
256 | Baz: t v | ||
257 | "#]], | ||
250 | ); | 258 | ); |
251 | assert_snapshot!(map, @r###" | ||
252 | ⋮crate | ||
253 | ⋮Bar: t v | ||
254 | ⋮Foo: t v | ||
255 | ⋮bar: t | ||
256 | ⋮foo: t | ||
257 | ⋮ | ||
258 | ⋮crate::bar | ||
259 | ⋮Baz: t v | ||
260 | "###); | ||
261 | } | 259 | } |
262 | 260 | ||
263 | #[test] | 261 | #[test] |
264 | fn prelude_is_macro_use() { | 262 | fn prelude_is_macro_use() { |
265 | mark::check!(prelude_is_macro_use); | 263 | mark::check!(prelude_is_macro_use); |
266 | let map = def_map( | 264 | check( |
267 | " | 265 | r#" |
268 | //- /main.rs crate:main deps:foo | 266 | //- /main.rs crate:main deps:foo |
269 | structs!(Foo); | 267 | structs!(Foo); |
270 | structs_priv!(Bar); | 268 | structs_priv!(Bar); |
271 | structs_outside!(Out); | 269 | structs_outside!(Out); |
272 | crate::structs!(MacroNotResolved2); | 270 | crate::structs!(MacroNotResolved2); |
273 | 271 | ||
274 | mod bar; | 272 | mod bar; |
275 | |||
276 | //- /bar.rs | ||
277 | structs!(Baz); | ||
278 | crate::structs!(MacroNotResolved3); | ||
279 | |||
280 | //- /lib.rs crate:foo | ||
281 | #[prelude_import] | ||
282 | use self::prelude::*; | ||
283 | |||
284 | mod prelude { | ||
285 | #[macro_export] | ||
286 | macro_rules! structs { | ||
287 | ($i:ident) => { struct $i; } | ||
288 | } | ||
289 | |||
290 | mod priv_mod { | ||
291 | #[macro_export] | ||
292 | macro_rules! structs_priv { | ||
293 | ($i:ident) => { struct $i; } | ||
294 | } | ||
295 | } | ||
296 | } | ||
297 | 273 | ||
274 | //- /bar.rs | ||
275 | structs!(Baz); | ||
276 | crate::structs!(MacroNotResolved3); | ||
277 | |||
278 | //- /lib.rs crate:foo | ||
279 | #[prelude_import] | ||
280 | use self::prelude::*; | ||
281 | |||
282 | mod prelude { | ||
283 | #[macro_export] | ||
284 | macro_rules! structs { | ||
285 | ($i:ident) => { struct $i; } | ||
286 | } | ||
287 | |||
288 | mod priv_mod { | ||
298 | #[macro_export] | 289 | #[macro_export] |
299 | macro_rules! structs_outside { | 290 | macro_rules! structs_priv { |
300 | ($i:ident) => { struct $i; } | 291 | ($i:ident) => { struct $i; } |
301 | } | 292 | } |
302 | ", | 293 | } |
294 | } | ||
295 | |||
296 | #[macro_export] | ||
297 | macro_rules! structs_outside { | ||
298 | ($i:ident) => { struct $i; } | ||
299 | } | ||
300 | "#, | ||
301 | expect![[r#" | ||
302 | crate | ||
303 | Bar: t v | ||
304 | Foo: t v | ||
305 | Out: t v | ||
306 | bar: t | ||
307 | |||
308 | crate::bar | ||
309 | Baz: t v | ||
310 | "#]], | ||
303 | ); | 311 | ); |
304 | assert_snapshot!(map, @r###" | ||
305 | ⋮crate | ||
306 | ⋮Bar: t v | ||
307 | ⋮Foo: t v | ||
308 | ⋮Out: t v | ||
309 | ⋮bar: t | ||
310 | ⋮ | ||
311 | ⋮crate::bar | ||
312 | ⋮Baz: t v | ||
313 | "###); | ||
314 | } | 312 | } |
315 | 313 | ||
316 | #[test] | 314 | #[test] |
317 | fn prelude_cycle() { | 315 | fn prelude_cycle() { |
318 | let map = def_map( | 316 | check( |
319 | " | 317 | r#" |
320 | //- /lib.rs | 318 | #[prelude_import] |
321 | #[prelude_import] | 319 | use self::prelude::*; |
322 | use self::prelude::*; | ||
323 | 320 | ||
324 | declare_mod!(); | 321 | declare_mod!(); |
325 | 322 | ||
326 | mod prelude { | 323 | mod prelude { |
327 | macro_rules! declare_mod { | 324 | macro_rules! declare_mod { |
328 | () => (mod foo {}) | 325 | () => (mod foo {}) |
329 | } | 326 | } |
330 | } | 327 | } |
331 | ", | 328 | "#, |
329 | expect![[r#" | ||
330 | crate | ||
331 | prelude: t | ||
332 | |||
333 | crate::prelude | ||
334 | "#]], | ||
332 | ); | 335 | ); |
333 | assert_snapshot!(map, @r###" | ||
334 | ⋮crate | ||
335 | ⋮prelude: t | ||
336 | ⋮ | ||
337 | ⋮crate::prelude | ||
338 | "###); | ||
339 | } | 336 | } |
340 | 337 | ||
341 | #[test] | 338 | #[test] |
342 | fn plain_macros_are_legacy_textual_scoped() { | 339 | fn plain_macros_are_legacy_textual_scoped() { |
343 | let map = def_map( | 340 | check( |
344 | r#" | 341 | r#" |
345 | //- /main.rs | 342 | //- /main.rs |
346 | mod m1; | 343 | mod m1; |
347 | bar!(NotFoundNotMacroUse); | 344 | bar!(NotFoundNotMacroUse); |
348 | 345 | ||
349 | mod m2 { | 346 | mod m2 { foo!(NotFoundBeforeInside2); } |
350 | foo!(NotFoundBeforeInside2); | ||
351 | } | ||
352 | 347 | ||
353 | macro_rules! foo { | 348 | macro_rules! foo { |
354 | ($x:ident) => { struct $x; } | 349 | ($x:ident) => { struct $x; } |
355 | } | 350 | } |
356 | foo!(Ok); | 351 | foo!(Ok); |
357 | |||
358 | mod m3; | ||
359 | foo!(OkShadowStop); | ||
360 | bar!(NotFoundMacroUseStop); | ||
361 | |||
362 | #[macro_use] | ||
363 | mod m5 { | ||
364 | #[macro_use] | ||
365 | mod m6 { | ||
366 | macro_rules! foo { | ||
367 | ($x:ident) => { fn $x() {} } | ||
368 | } | ||
369 | } | ||
370 | } | ||
371 | foo!(ok_double_macro_use_shadow); | ||
372 | |||
373 | baz!(NotFoundBefore); | ||
374 | #[macro_use] | ||
375 | mod m7 { | ||
376 | macro_rules! baz { | ||
377 | ($x:ident) => { struct $x; } | ||
378 | } | ||
379 | } | ||
380 | baz!(OkAfter); | ||
381 | 352 | ||
382 | //- /m1.rs | 353 | mod m3; |
383 | foo!(NotFoundBeforeInside1); | 354 | foo!(OkShadowStop); |
384 | macro_rules! bar { | 355 | bar!(NotFoundMacroUseStop); |
385 | ($x:ident) => { struct $x; } | ||
386 | } | ||
387 | 356 | ||
388 | //- /m3/mod.rs | 357 | #[macro_use] |
389 | foo!(OkAfterInside); | 358 | mod m5 { |
359 | #[macro_use] | ||
360 | mod m6 { | ||
390 | macro_rules! foo { | 361 | macro_rules! foo { |
391 | ($x:ident) => { fn $x() {} } | 362 | ($x:ident) => { fn $x() {} } |
392 | } | 363 | } |
393 | foo!(ok_shadow); | 364 | } |
365 | } | ||
366 | foo!(ok_double_macro_use_shadow); | ||
367 | |||
368 | baz!(NotFoundBefore); | ||
369 | #[macro_use] | ||
370 | mod m7 { | ||
371 | macro_rules! baz { | ||
372 | ($x:ident) => { struct $x; } | ||
373 | } | ||
374 | } | ||
375 | baz!(OkAfter); | ||
394 | 376 | ||
395 | #[macro_use] | 377 | //- /m1.rs |
396 | mod m4; | 378 | foo!(NotFoundBeforeInside1); |
397 | bar!(OkMacroUse); | 379 | macro_rules! bar { |
380 | ($x:ident) => { struct $x; } | ||
381 | } | ||
398 | 382 | ||
399 | //- /m3/m4.rs | 383 | //- /m3/mod.rs |
400 | foo!(ok_shadow_deep); | 384 | foo!(OkAfterInside); |
401 | macro_rules! bar { | 385 | macro_rules! foo { |
402 | ($x:ident) => { struct $x; } | 386 | ($x:ident) => { fn $x() {} } |
403 | } | 387 | } |
404 | "#, | 388 | foo!(ok_shadow); |
389 | |||
390 | #[macro_use] | ||
391 | mod m4; | ||
392 | bar!(OkMacroUse); | ||
393 | |||
394 | //- /m3/m4.rs | ||
395 | foo!(ok_shadow_deep); | ||
396 | macro_rules! bar { | ||
397 | ($x:ident) => { struct $x; } | ||
398 | } | ||
399 | "#, | ||
400 | expect![[r#" | ||
401 | crate | ||
402 | Ok: t v | ||
403 | OkAfter: t v | ||
404 | OkShadowStop: t v | ||
405 | m1: t | ||
406 | m2: t | ||
407 | m3: t | ||
408 | m5: t | ||
409 | m7: t | ||
410 | ok_double_macro_use_shadow: v | ||
411 | |||
412 | crate::m7 | ||
413 | |||
414 | crate::m1 | ||
415 | |||
416 | crate::m5 | ||
417 | m6: t | ||
418 | |||
419 | crate::m5::m6 | ||
420 | |||
421 | crate::m2 | ||
422 | |||
423 | crate::m3 | ||
424 | OkAfterInside: t v | ||
425 | OkMacroUse: t v | ||
426 | m4: t | ||
427 | ok_shadow: v | ||
428 | |||
429 | crate::m3::m4 | ||
430 | ok_shadow_deep: v | ||
431 | "#]], | ||
405 | ); | 432 | ); |
406 | assert_snapshot!(map, @r###" | ||
407 | ⋮crate | ||
408 | ⋮Ok: t v | ||
409 | ⋮OkAfter: t v | ||
410 | ⋮OkShadowStop: t v | ||
411 | ⋮m1: t | ||
412 | ⋮m2: t | ||
413 | ⋮m3: t | ||
414 | ⋮m5: t | ||
415 | ⋮m7: t | ||
416 | ⋮ok_double_macro_use_shadow: v | ||
417 | ⋮ | ||
418 | ⋮crate::m7 | ||
419 | ⋮ | ||
420 | ⋮crate::m1 | ||
421 | ⋮ | ||
422 | ⋮crate::m5 | ||
423 | ⋮m6: t | ||
424 | ⋮ | ||
425 | ⋮crate::m5::m6 | ||
426 | ⋮ | ||
427 | ⋮crate::m2 | ||
428 | ⋮ | ||
429 | ⋮crate::m3 | ||
430 | ⋮OkAfterInside: t v | ||
431 | ⋮OkMacroUse: t v | ||
432 | ⋮m4: t | ||
433 | ⋮ok_shadow: v | ||
434 | ⋮ | ||
435 | ⋮crate::m3::m4 | ||
436 | ⋮ok_shadow_deep: v | ||
437 | "###); | ||
438 | } | 433 | } |
439 | 434 | ||
440 | #[test] | 435 | #[test] |
441 | fn type_value_macro_live_in_different_scopes() { | 436 | fn type_value_macro_live_in_different_scopes() { |
442 | let map = def_map( | 437 | check( |
443 | " | 438 | r#" |
444 | //- /main.rs | 439 | #[macro_export] |
445 | #[macro_export] | 440 | macro_rules! foo { |
446 | macro_rules! foo { | 441 | ($x:ident) => { type $x = (); } |
447 | ($x:ident) => { type $x = (); } | 442 | } |
448 | } | ||
449 | |||
450 | foo!(foo); | ||
451 | use foo as bar; | ||
452 | 443 | ||
453 | use self::foo as baz; | 444 | foo!(foo); |
454 | fn baz() {} | 445 | use foo as bar; |
455 | ", | 446 | |
447 | use self::foo as baz; | ||
448 | fn baz() {} | ||
449 | "#, | ||
450 | expect![[r#" | ||
451 | crate | ||
452 | bar: t m | ||
453 | baz: t v m | ||
454 | foo: t m | ||
455 | "#]], | ||
456 | ); | 456 | ); |
457 | assert_snapshot!(map, @r###" | ||
458 | ⋮crate | ||
459 | ⋮bar: t m | ||
460 | ⋮baz: t v m | ||
461 | ⋮foo: t m | ||
462 | "###); | ||
463 | } | 457 | } |
464 | 458 | ||
465 | #[test] | 459 | #[test] |
466 | fn macro_use_can_be_aliased() { | 460 | fn macro_use_can_be_aliased() { |
467 | let map = def_map( | 461 | check( |
468 | " | 462 | r#" |
469 | //- /main.rs crate:main deps:foo | 463 | //- /main.rs crate:main deps:foo |
470 | #[macro_use] | 464 | #[macro_use] |
471 | extern crate foo; | 465 | extern crate foo; |
472 | 466 | ||
473 | foo!(Direct); | 467 | foo!(Direct); |
474 | bar!(Alias); | 468 | bar!(Alias); |
475 | 469 | ||
476 | //- /lib.rs crate:foo | 470 | //- /lib.rs crate:foo |
477 | use crate::foo as bar; | 471 | use crate::foo as bar; |
478 | 472 | ||
479 | mod m { | 473 | mod m { |
480 | #[macro_export] | 474 | #[macro_export] |
481 | macro_rules! foo { | 475 | macro_rules! foo { |
482 | ($x:ident) => { struct $x; } | 476 | ($x:ident) => { struct $x; } |
483 | } | 477 | } |
484 | } | 478 | } |
485 | ", | 479 | "#, |
480 | expect![[r#" | ||
481 | crate | ||
482 | Alias: t v | ||
483 | Direct: t v | ||
484 | foo: t | ||
485 | "#]], | ||
486 | ); | 486 | ); |
487 | assert_snapshot!(map, @r###" | ||
488 | ⋮crate | ||
489 | ⋮Alias: t v | ||
490 | ⋮Direct: t v | ||
491 | ⋮foo: t | ||
492 | "###); | ||
493 | } | 487 | } |
494 | 488 | ||
495 | #[test] | 489 | #[test] |
496 | fn path_qualified_macros() { | 490 | fn path_qualified_macros() { |
497 | let map = def_map( | 491 | check( |
498 | " | 492 | r#" |
499 | //- /main.rs | 493 | macro_rules! foo { |
500 | macro_rules! foo { | 494 | ($x:ident) => { struct $x; } |
501 | ($x:ident) => { struct $x; } | 495 | } |
502 | } | ||
503 | 496 | ||
504 | crate::foo!(NotResolved); | 497 | crate::foo!(NotResolved); |
505 | 498 | ||
506 | crate::bar!(OkCrate); | 499 | crate::bar!(OkCrate); |
507 | bar!(OkPlain); | 500 | bar!(OkPlain); |
508 | alias1!(NotHere); | 501 | alias1!(NotHere); |
509 | m::alias1!(OkAliasPlain); | 502 | m::alias1!(OkAliasPlain); |
510 | m::alias2!(OkAliasSuper); | 503 | m::alias2!(OkAliasSuper); |
511 | m::alias3!(OkAliasCrate); | 504 | m::alias3!(OkAliasCrate); |
512 | not_found!(NotFound); | 505 | not_found!(NotFound); |
513 | 506 | ||
514 | mod m { | 507 | mod m { |
515 | #[macro_export] | 508 | #[macro_export] |
516 | macro_rules! bar { | 509 | macro_rules! bar { |
517 | ($x:ident) => { struct $x; } | 510 | ($x:ident) => { struct $x; } |
518 | } | 511 | } |
519 | 512 | pub use bar as alias1; | |
520 | pub use bar as alias1; | 513 | pub use super::bar as alias2; |
521 | pub use super::bar as alias2; | 514 | pub use crate::bar as alias3; |
522 | pub use crate::bar as alias3; | 515 | pub use self::bar as not_found; |
523 | pub use self::bar as not_found; | 516 | } |
524 | } | 517 | "#, |
525 | ", | 518 | expect![[r#" |
519 | crate | ||
520 | OkAliasCrate: t v | ||
521 | OkAliasPlain: t v | ||
522 | OkAliasSuper: t v | ||
523 | OkCrate: t v | ||
524 | OkPlain: t v | ||
525 | bar: m | ||
526 | m: t | ||
527 | |||
528 | crate::m | ||
529 | alias1: m | ||
530 | alias2: m | ||
531 | alias3: m | ||
532 | not_found: _ | ||
533 | "#]], | ||
526 | ); | 534 | ); |
527 | assert_snapshot!(map, @r###" | ||
528 | ⋮crate | ||
529 | ⋮OkAliasCrate: t v | ||
530 | ⋮OkAliasPlain: t v | ||
531 | ⋮OkAliasSuper: t v | ||
532 | ⋮OkCrate: t v | ||
533 | ⋮OkPlain: t v | ||
534 | ⋮bar: m | ||
535 | ⋮m: t | ||
536 | ⋮ | ||
537 | ⋮crate::m | ||
538 | ⋮alias1: m | ||
539 | ⋮alias2: m | ||
540 | ⋮alias3: m | ||
541 | ⋮not_found: _ | ||
542 | "###); | ||
543 | } | 535 | } |
544 | 536 | ||
545 | #[test] | 537 | #[test] |
546 | fn macro_dollar_crate_is_correct_in_item() { | 538 | fn macro_dollar_crate_is_correct_in_item() { |
547 | mark::check!(macro_dollar_crate_self); | 539 | mark::check!(macro_dollar_crate_self); |
548 | let map = def_map( | 540 | check( |
549 | " | 541 | r#" |
550 | //- /main.rs crate:main deps:foo | 542 | //- /main.rs crate:main deps:foo |
551 | #[macro_use] | 543 | #[macro_use] |
552 | extern crate foo; | 544 | extern crate foo; |
553 | 545 | ||
554 | #[macro_use] | 546 | #[macro_use] |
555 | mod m { | 547 | mod m { |
556 | macro_rules! current { | 548 | macro_rules! current { |
557 | () => { | 549 | () => { |
558 | use $crate::Foo as FooSelf; | 550 | use $crate::Foo as FooSelf; |
559 | } | ||
560 | } | ||
561 | } | 551 | } |
552 | } | ||
553 | } | ||
562 | 554 | ||
563 | struct Foo; | 555 | struct Foo; |
564 | 556 | ||
565 | current!(); | 557 | current!(); |
566 | not_current1!(); | 558 | not_current1!(); |
567 | foo::not_current2!(); | 559 | foo::not_current2!(); |
568 | |||
569 | //- /lib.rs crate:foo | ||
570 | mod m { | ||
571 | #[macro_export] | ||
572 | macro_rules! not_current1 { | ||
573 | () => { | ||
574 | use $crate::Bar; | ||
575 | } | ||
576 | } | ||
577 | } | ||
578 | 560 | ||
579 | #[macro_export] | 561 | //- /lib.rs crate:foo |
580 | macro_rules! not_current2 { | 562 | mod m { |
581 | () => { | 563 | #[macro_export] |
582 | use $crate::Baz; | 564 | macro_rules! not_current1 { |
583 | } | 565 | () => { |
566 | use $crate::Bar; | ||
584 | } | 567 | } |
568 | } | ||
569 | } | ||
585 | 570 | ||
586 | struct Bar; | 571 | #[macro_export] |
587 | struct Baz; | 572 | macro_rules! not_current2 { |
588 | ", | 573 | () => { |
574 | use $crate::Baz; | ||
575 | } | ||
576 | } | ||
577 | |||
578 | struct Bar; | ||
579 | struct Baz; | ||
580 | "#, | ||
581 | expect![[r#" | ||
582 | crate | ||
583 | Bar: t v | ||
584 | Baz: t v | ||
585 | Foo: t v | ||
586 | FooSelf: t v | ||
587 | foo: t | ||
588 | m: t | ||
589 | |||
590 | crate::m | ||
591 | "#]], | ||
589 | ); | 592 | ); |
590 | assert_snapshot!(map, @r###" | ||
591 | ⋮crate | ||
592 | ⋮Bar: t v | ||
593 | ⋮Baz: t v | ||
594 | ⋮Foo: t v | ||
595 | ⋮FooSelf: t v | ||
596 | ⋮foo: t | ||
597 | ⋮m: t | ||
598 | ⋮ | ||
599 | ⋮crate::m | ||
600 | "###); | ||
601 | } | 593 | } |
602 | 594 | ||
603 | #[test] | 595 | #[test] |
604 | fn macro_dollar_crate_is_correct_in_indirect_deps() { | 596 | fn macro_dollar_crate_is_correct_in_indirect_deps() { |
605 | mark::check!(macro_dollar_crate_other); | 597 | mark::check!(macro_dollar_crate_other); |
606 | // From std | 598 | // From std |
607 | let map = def_map( | 599 | check( |
608 | r#" | 600 | r#" |
609 | //- /main.rs crate:main deps:std | 601 | //- /main.rs crate:main deps:std |
610 | foo!(); | 602 | foo!(); |
611 | 603 | ||
612 | //- /std.rs crate:std deps:core | 604 | //- /std.rs crate:std deps:core |
613 | #[prelude_import] | 605 | #[prelude_import] |
614 | use self::prelude::*; | 606 | use self::prelude::*; |
615 | 607 | ||
616 | pub use core::foo; | 608 | pub use core::foo; |
617 | 609 | ||
618 | mod prelude {} | 610 | mod prelude {} |
619 | 611 | ||
620 | #[macro_use] | 612 | #[macro_use] |
621 | mod std_macros; | 613 | mod std_macros; |
622 | 614 | ||
623 | //- /core.rs crate:core | 615 | //- /core.rs crate:core |
624 | #[macro_export] | 616 | #[macro_export] |
625 | macro_rules! foo { | 617 | macro_rules! foo { |
626 | () => { | 618 | () => { |
627 | use $crate::bar; | 619 | use $crate::bar; |
628 | } | 620 | } |
629 | } | 621 | } |
630 | 622 | ||
631 | pub struct bar; | 623 | pub struct bar; |
632 | "#, | 624 | "#, |
625 | expect![[r#" | ||
626 | crate | ||
627 | bar: t v | ||
628 | "#]], | ||
633 | ); | 629 | ); |
634 | assert_snapshot!(map, @r###" | ||
635 | ⋮crate | ||
636 | ⋮bar: t v | ||
637 | "###); | ||
638 | } | 630 | } |
639 | 631 | ||
640 | #[test] | 632 | #[test] |
@@ -642,21 +634,36 @@ fn expand_derive() { | |||
642 | let map = compute_crate_def_map( | 634 | let map = compute_crate_def_map( |
643 | " | 635 | " |
644 | //- /main.rs | 636 | //- /main.rs |
645 | #[derive(Clone)] | 637 | #[derive(Copy, Clone)] |
646 | struct Foo; | 638 | struct Foo; |
647 | ", | 639 | ", |
648 | ); | 640 | ); |
649 | assert_eq!(map.modules[map.root].scope.impls().len(), 1); | 641 | assert_eq!(map.modules[map.root].scope.impls().len(), 2); |
650 | } | 642 | } |
651 | 643 | ||
652 | #[test] | 644 | #[test] |
653 | fn expand_multiple_derive() { | 645 | fn macro_expansion_overflow() { |
654 | let map = compute_crate_def_map( | 646 | mark::check!(macro_expansion_overflow); |
655 | " | 647 | check( |
656 | //- /main.rs | 648 | r#" |
657 | #[derive(Copy, Clone)] | 649 | macro_rules! a { |
658 | struct Foo; | 650 | ($e:expr; $($t:tt)*) => { |
659 | ", | 651 | b!($($t)*); |
652 | }; | ||
653 | () => {}; | ||
654 | } | ||
655 | |||
656 | macro_rules! b { | ||
657 | (static = $e:expr; $($t:tt)*) => { | ||
658 | a!($e; $($t)*); | ||
659 | }; | ||
660 | () => {}; | ||
661 | } | ||
662 | |||
663 | b! { static = #[] (); } | ||
664 | "#, | ||
665 | expect![[r#" | ||
666 | crate | ||
667 | "#]], | ||
660 | ); | 668 | ); |
661 | assert_eq!(map.modules[map.root].scope.impls().len(), 2); | ||
662 | } | 669 | } |