]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
0bf4aa26 XL |
2 | #![allow(dead_code)] |
3 | #![allow(unused_mut)] | |
4 | #![allow(unused_variables)] | |
92a42be0 SL |
5 | #![deny(non_snake_case)] |
6 | #![feature(stmt_expr_attributes)] | |
7 | ||
8 | fn main() { | |
9 | let a = 413; | |
10 | #[cfg(unset)] | |
11 | let a = (); | |
12 | assert_eq!(a, 413); | |
13 | ||
14 | let mut b = 612; | |
15 | #[cfg(unset)] | |
16 | { | |
17 | b = 1111; | |
18 | } | |
19 | assert_eq!(b, 612); | |
20 | ||
21 | #[cfg(unset)] | |
22 | undefined_fn(); | |
23 | ||
24 | #[cfg(unset)] | |
25 | undefined_macro!(); | |
26 | #[cfg(unset)] | |
27 | undefined_macro![]; | |
28 | #[cfg(unset)] | |
29 | undefined_macro!{}; | |
30 | ||
31 | // pretty printer bug... | |
32 | // #[cfg(unset)] | |
33 | // undefined_macro!{} | |
34 | ||
35 | let () = (#[cfg(unset)] 341,); // Should this also work on parens? | |
36 | let t = (1, #[cfg(unset)] 3, 4); | |
37 | assert_eq!(t, (1, 4)); | |
38 | ||
39 | let f = |_: u32, _: u32| (); | |
40 | f(2, 1, #[cfg(unset)] 6); | |
41 | ||
42 | let _: u32 = a.clone(#[cfg(unset)] undefined); | |
43 | ||
44 | let _: [(); 0] = [#[cfg(unset)] 126]; | |
45 | let t = [#[cfg(unset)] 1, 2, 6]; | |
46 | assert_eq!(t, [2, 6]); | |
47 | ||
48 | { | |
49 | let r; | |
50 | #[cfg(unset)] | |
51 | (r = 5); | |
52 | #[cfg(not(unset))] | |
53 | (r = 10); | |
54 | assert_eq!(r, 10); | |
55 | } | |
56 | ||
57 | // check that macro expanded code works | |
58 | ||
59 | macro_rules! if_cfg { | |
e74abb32 | 60 | ($cfg:meta? $ib:block else $eb:block) => { |
92a42be0 SL |
61 | { |
62 | let r; | |
63 | #[cfg($cfg)] | |
64 | (r = $ib); | |
65 | #[cfg(not($cfg))] | |
66 | (r = $eb); | |
67 | r | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
e74abb32 | 72 | let n = if_cfg!(unset? { |
92a42be0 SL |
73 | 413 |
74 | } else { | |
75 | 612 | |
76 | }); | |
77 | ||
78 | assert_eq!((#[cfg(unset)] 1, #[cfg(not(unset))] 2), (2,)); | |
79 | assert_eq!(n, 612); | |
80 | ||
81 | // check that lints work | |
82 | ||
83 | #[allow(non_snake_case)] | |
84 | let FOOBAR = { | |
85 | fn SYLADEX() {} | |
86 | }; | |
87 | ||
88 | #[allow(non_snake_case)] | |
89 | { | |
90 | fn CRUXTRUDER() {} | |
91 | } | |
92 | } |