summaryrefslogtreecommitdiffstats
path: root/tests/ui/hygiene/auxiliary/unhygienic_example.rs
blob: 8e6e8f9b32f979ccd399945a1da67869bf5d6b1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#![crate_type = "lib"]

extern crate my_crate;

pub fn g() {} // (a)

#[macro_export]
macro_rules! unhygienic_macro {
    () => {
        // (1) unhygienic: depends on `my_crate` in the crate root at the invocation site.
        ::my_crate::f();

        // (2) unhygienic: defines `f` at the invocation site (in addition to the above point).
        use my_crate::f;
        f();

        g(); // (3) unhygienic: `g` needs to be in scope at use site.

        $crate::g(); // (4) hygienic: this always resolves to (a)
    }
}

#[allow(unused)]
fn test_unhygienic() {
    unhygienic_macro!();
    f(); // `f` was defined at the use site
}