]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/conditional-compile.rs
Auto merge of #28816 - petrochenkov:unistruct, r=nrc
[rust.git] / src / test / run-pass / conditional-compile.rs
1 // Copyright 2012-2014 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 // Crate use statements
12
13 #[cfg(bogus)]
14 use flippity;
15
16 #[cfg(bogus)]
17 static b: bool = false;
18
19 static b: bool = true;
20
21 mod rustrt {
22     #[cfg(bogus)]
23     extern {
24         // This symbol doesn't exist and would be a link error if this
25         // module was translated
26         pub fn bogus();
27     }
28
29     extern {}
30 }
31
32 #[cfg(bogus)]
33 type t = isize;
34
35 type t = bool;
36
37 #[cfg(bogus)]
38 enum tg { foo, }
39
40 enum tg { bar, }
41
42 #[cfg(bogus)]
43 struct r {
44   i: isize,
45 }
46
47 #[cfg(bogus)]
48 fn r(i:isize) -> r {
49     r {
50         i: i
51     }
52 }
53
54 struct r {
55   i: isize,
56 }
57
58 fn r(i:isize) -> r {
59     r {
60         i: i
61     }
62 }
63
64 #[cfg(bogus)]
65 mod m {
66     // This needs to parse but would fail in typeck. Since it's not in
67     // the current config it should not be typechecked.
68     pub fn bogus() { return 0; }
69 }
70
71 mod m {
72     // Submodules have slightly different code paths than the top-level
73     // module, so let's make sure this jazz works here as well
74     #[cfg(bogus)]
75     pub fn f() { }
76
77     pub fn f() { }
78 }
79
80 // Since the bogus configuration isn't defined main will just be
81 // parsed, but nothing further will be done with it
82 #[cfg(bogus)]
83 pub fn main() { panic!() }
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() { panic!() }
98     fn f() { }
99     f();
100
101     #[cfg(bogus)]
102     static i: isize = 0;
103     static i: isize = 1;
104     assert_eq!(i, 1);
105 }
106
107 mod test_foreign_items {
108     pub mod rustrt {
109         extern {
110             #[cfg(bogus)]
111             pub fn write() -> String;
112             pub fn write() -> String;
113         }
114     }
115 }
116
117 mod test_use_statements {
118     #[cfg(bogus)]
119     use flippity_foo;
120 }
121
122 mod test_methods {
123     struct Foo {
124         bar: usize
125     }
126
127     impl Fooable for Foo {
128         #[cfg(bogus)]
129         fn what(&self) { }
130
131         fn what(&self) { }
132
133         #[cfg(bogus)]
134         fn the(&self) { }
135
136         fn the(&self) { }
137     }
138
139     trait Fooable {
140         #[cfg(bogus)]
141         fn what(&self);
142
143         fn what(&self);
144
145         #[cfg(bogus)]
146         fn the(&self);
147
148         fn the(&self);
149     }
150 }