]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hygiene/globs.rs
Rollup merge of #54838 - 11Takanori:fix-typo, r=petrochenkov
[rust.git] / src / test / ui / hygiene / globs.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 #![feature(decl_macro)]
12
13 mod foo {
14     pub fn f() {}
15 }
16
17 mod bar {
18     pub fn g() {}
19 }
20
21 macro m($($t:tt)*) {
22     $($t)*
23     use foo::*;
24     f();
25     g(); //~ ERROR cannot find function `g` in this scope
26 }
27
28 fn main() {
29     m! {
30         use bar::*;
31         g();
32         f(); //~ ERROR cannot find function `f` in this scope
33     }
34 }
35
36 n!(f);
37 macro n($i:ident) {
38     mod foo {
39         pub fn $i() -> u32 { 0 }
40         pub fn f() {}
41
42         mod test {
43             use super::*;
44             fn g() {
45                 let _: u32 = $i();
46                 let _: () = f();
47             }
48         }
49
50         macro n($j:ident) {
51             mod test {
52                 use super::*;
53                 fn g() {
54                     let _: u32 = $i();
55                     let _: () = f();
56                     $j();
57                 }
58             }
59         }
60         macro n_with_super($j:ident) {
61             mod test {
62                 use super::*;
63                 fn g() {
64                     let _: u32 = $i();
65                     let _: () = f();
66                     super::$j();
67                 }
68             }
69         }
70
71         n!(f); //~ ERROR cannot find function `f` in this scope
72         n_with_super!(f);
73         mod test2 {
74             super::n! {
75                 f //~ ERROR cannot find function `f` in this scope
76             }
77             super::n_with_super! {
78                 f
79             }
80         }
81     }
82 }