]>
git.proxmox.com Git - rustc.git/blob - 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.
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.
12 // ignore-pretty pretty-printing is unhygienic
14 // aux-build:my_crate.rs
15 // aux-build:unhygienic_example.rs
17 #![feature(decl_macro)]
19 extern crate unhygienic_example
;
20 extern crate my_crate
; // (b)
22 // Hygienic version of `unhygienic_macro`.
23 pub macro hygienic_macro() {
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).
37 fn test_hygienic_macro() {
40 fn f() {}
// (d) no conflict
41 f(); // resolves to (d)