]> git.proxmox.com Git - rustc.git/blob - src/test/ui/cfg/cfg_stmt_expr.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / test / ui / cfg / cfg_stmt_expr.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_mut)]
4 #![allow(unused_variables)]
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 {
60 ($cfg:meta $ib:block else $eb:block) => {
61 {
62 let r;
63 #[cfg($cfg)]
64 (r = $ib);
65 #[cfg(not($cfg))]
66 (r = $eb);
67 r
68 }
69 }
70 }
71
72 let n = if_cfg!(unset {
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 }