summaryrefslogtreecommitdiffstats
path: root/tests/ui/cfg/cfg_stmt_expr.rs
blob: f9f4c98102c9903b96d05ddbadb61efccea7f3c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// run-pass
#![allow(dead_code)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![deny(non_snake_case)]
#![feature(stmt_expr_attributes)]

fn main() {
    let a = 413;
    #[cfg(unset)]
    let a = ();
    assert_eq!(a, 413);

    let mut b = 612;
    #[cfg(unset)]
    {
        b = 1111;
    }
    assert_eq!(b, 612);

    #[cfg(unset)]
    undefined_fn();

    #[cfg(unset)]
    undefined_macro!();
    #[cfg(unset)]
    undefined_macro![];
    #[cfg(unset)]
    undefined_macro!{};

    // pretty printer bug...
    // #[cfg(unset)]
    // undefined_macro!{}

    let () = (#[cfg(unset)] 341,); // Should this also work on parens?
    let t = (1, #[cfg(unset)] 3, 4);
    assert_eq!(t, (1, 4));

    let f = |_: u32, _: u32| ();
    f(2, 1, #[cfg(unset)] 6);

    let _: u32 = a.clone(#[cfg(unset)] undefined);

    let _: [(); 0] = [#[cfg(unset)] 126];
    let t = [#[cfg(unset)] 1, 2, 6];
    assert_eq!(t, [2, 6]);

    {
        let r;
        #[cfg(unset)]
        (r = 5);
        #[cfg(not(unset))]
        (r = 10);
        assert_eq!(r, 10);
    }

    // check that macro expanded code works

    macro_rules! if_cfg {
        ($cfg:meta? $ib:block else $eb:block) => {
            {
                let r;
                #[cfg($cfg)]
                (r = $ib);
                #[cfg(not($cfg))]
                (r = $eb);
                r
            }
        }
    }

    let n = if_cfg!(unset? {
        413
    } else {
        612
    });

    assert_eq!((#[cfg(unset)] 1, #[cfg(not(unset))] 2), (2,));
    assert_eq!(n, 612);

    // check that lints work

    #[allow(non_snake_case)]
    let FOOBAR: () = {
        fn SYLADEX() {}
    };

    #[allow(non_snake_case)]
    {
        fn CRUXTRUDER() {}
    }
}