]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cfg/conditional-compile.rs
Rollup merge of #97786 - ferrocene:pa-fix-simulate-remap-prefix, r=Mark-Simulacrum
[rust.git] / src / test / ui / cfg / conditional-compile.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(non_upper_case_globals)]
4 #![allow(non_camel_case_types)]
5 #![allow(improper_ctypes)]
6
7 // Crate use statements
8
9 #[cfg(bogus)]
10 use flippity;
11
12 #[cfg(bogus)]
13 static b: bool = false;
14
15 static b: bool = true;
16
17 mod rustrt {
18     #[cfg(bogus)]
19     extern "C" {
20         // This symbol doesn't exist and would be a link error if this
21         // module was codegened
22         pub fn bogus();
23     }
24
25     extern "C" {}
26 }
27
28 #[cfg(bogus)]
29 type t = isize;
30
31 type t = bool;
32
33 #[cfg(bogus)]
34 enum tg {
35     foo,
36 }
37
38 enum tg {
39     bar,
40 }
41
42 #[cfg(bogus)]
43 struct r {
44     i: isize,
45 }
46
47 #[cfg(bogus)]
48 fn r(i: isize) -> r {
49     r { i: i }
50 }
51
52 struct r {
53     i: isize,
54 }
55
56 fn r(i: isize) -> r {
57     r { i: i }
58 }
59
60 #[cfg(bogus)]
61 mod m {
62     // This needs to parse but would fail in typeck. Since it's not in
63     // the current config it should not be typechecked.
64     pub fn bogus() {
65         return 0;
66     }
67 }
68
69 mod m {
70     // Submodules have slightly different code paths than the top-level
71     // module, so let's make sure this jazz works here as well
72     #[cfg(bogus)]
73     pub fn f() {}
74
75     pub fn f() {}
76 }
77
78 // Since the bogus configuration isn't defined main will just be
79 // parsed, but nothing further will be done with it
80 #[cfg(bogus)]
81 pub fn main() {
82     panic!()
83 }
84
85 pub fn main() {
86     // Exercise some of the configured items in ways that wouldn't be possible
87     // if they had the bogus definition
88     assert!((b));
89     let _x: t = true;
90     let _y: tg = tg::bar;
91
92     test_in_fn_ctxt();
93 }
94
95 fn test_in_fn_ctxt() {
96     #[cfg(bogus)]
97     fn f() {
98         panic!()
99     }
100     fn f() {}
101     f();
102
103     #[cfg(bogus)]
104     static i: isize = 0;
105     static i: isize = 1;
106     assert_eq!(i, 1);
107 }
108
109 mod test_foreign_items {
110     pub mod rustrt {
111         extern "C" {
112             #[cfg(bogus)]
113             pub fn write() -> String;
114             pub fn write() -> String;
115         }
116     }
117 }
118
119 mod test_use_statements {
120     #[cfg(bogus)]
121     use flippity_foo;
122 }
123
124 mod test_methods {
125     struct Foo {
126         bar: usize,
127     }
128
129     impl Fooable for Foo {
130         #[cfg(bogus)]
131         fn what(&self) {}
132
133         fn what(&self) {}
134
135         #[cfg(bogus)]
136         fn the(&self) {}
137
138         fn the(&self) {}
139     }
140
141     trait Fooable {
142         #[cfg(bogus)]
143         fn what(&self);
144
145         fn what(&self);
146
147         #[cfg(bogus)]
148         fn the(&self);
149
150         fn the(&self);
151     }
152 }
153
154 #[cfg(any())]
155 mod nonexistent_file; // Check that unconfigured non-inline modules are not loaded or parsed.