]> git.lizzy.rs Git - rust.git/blob - src/test/ui/hygiene/generate-mod.rs
Auto merge of #53815 - F001:if-let-guard, r=petrochenkov
[rust.git] / src / test / ui / hygiene / generate-mod.rs
1 // Copyright 2018 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 // This is an equivalent of issue #50504, but for declarative macros.
12
13 #![feature(decl_macro, rustc_attrs)]
14
15 macro genmod($FromOutside: ident, $Outer: ident) {
16     type A = $FromOutside;
17     struct $Outer;
18     mod inner {
19         type A = $FromOutside; // `FromOutside` shouldn't be available from here
20         type Inner = $Outer; // `Outer` shouldn't be available from here
21     }
22 }
23
24 #[rustc_transparent_macro]
25 macro genmod_transparent() {
26     type A = FromOutside;
27     struct Outer;
28     mod inner {
29         type A = FromOutside; //~ ERROR cannot find type `FromOutside` in this scope
30         type Inner = Outer; //~ ERROR cannot find type `Outer` in this scope
31     }
32 }
33
34 macro_rules! genmod_legacy { () => {
35     type A = FromOutside;
36     struct Outer;
37     mod inner {
38         type A = FromOutside; //~ ERROR cannot find type `FromOutside` in this scope
39         type Inner = Outer; //~ ERROR cannot find type `Outer` in this scope
40     }
41 }}
42
43 fn check() {
44     struct FromOutside;
45     genmod!(FromOutside, Outer); //~ ERROR cannot find type `FromOutside` in this scope
46                                  //~| ERROR cannot find type `Outer` in this scope
47 }
48
49 fn check_transparent() {
50     struct FromOutside;
51     genmod_transparent!();
52 }
53
54 fn check_legacy() {
55     struct FromOutside;
56     genmod_legacy!();
57 }
58
59 fn main() {}