]>
Commit | Line | Data |
---|---|---|
416331ca | 1 | // check-pass |
2c00a5a8 XL |
2 | // ignore-pretty pretty-printing is unhygienic |
3 | ||
4 | // aux-build:my_crate.rs | |
5 | // aux-build:unhygienic_example.rs | |
6 | ||
7 | #![feature(decl_macro)] | |
8 | ||
9 | extern crate unhygienic_example; | |
10 | extern crate my_crate; // (b) | |
11 | ||
12 | // Hygienic version of `unhygienic_macro`. | |
13 | pub macro hygienic_macro() { | |
14 | fn g() {} // (c) | |
15 | ::unhygienic_example::unhygienic_macro!(); | |
16 | // ^ Even though we invoke an unhygienic macro, `hygienic_macro` remains hygienic. | |
17 | // In the above expansion: | |
18 | // (1) `my_crate` always resolves to (b) regardless of invocation site. | |
19 | // (2) The defined function `f` is only usable inside this macro definition. | |
20 | // (3) `g` always resolves to (c) regardless of invocation site. | |
21 | // (4) `$crate::g` remains hygienic and continues to resolve to (a). | |
22 | ||
23 | f(); | |
24 | } | |
25 | ||
26 | #[allow(unused)] | |
27 | fn test_hygienic_macro() { | |
28 | hygienic_macro!(); | |
29 | ||
30 | fn f() {} // (d) no conflict | |
31 | f(); // resolves to (d) | |
32 | } | |
33 | ||
34 | fn main() {} |