]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/hygiene/wrap_unhygienic_example.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / run-pass / hygiene / wrap_unhygienic_example.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // run-pass
12 // ignore-pretty pretty-printing is unhygienic
13
14 // aux-build:my_crate.rs
15 // aux-build:unhygienic_example.rs
16
17 #![feature(decl_macro)]
18
19 extern crate unhygienic_example;
20 extern crate my_crate; // (b)
21
22 // Hygienic version of `unhygienic_macro`.
23 pub macro hygienic_macro() {
24 fn g() {} // (c)
25 ::unhygienic_example::unhygienic_macro!();
26 // ^ Even though we invoke an unhygienic macro, `hygienic_macro` remains hygienic.
27 // In the above expansion:
28 // (1) `my_crate` always resolves to (b) regardless of invocation site.
29 // (2) The defined function `f` is only usable inside this macro definition.
30 // (3) `g` always resolves to (c) regardless of invocation site.
31 // (4) `$crate::g` remains hygienic and continues to resolve to (a).
32
33 f();
34 }
35
36 #[allow(unused)]
37 fn test_hygienic_macro() {
38 hygienic_macro!();
39
40 fn f() {} // (d) no conflict
41 f(); // resolves to (d)
42 }
43
44 fn main() {}