about summary refs log tree commit diff
path: root/tests/ui/macros/cfg_select.rs
blob: 9241141ef9a6cf7b8d5a516e6f1fb34cb9532126 (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
#![feature(cfg_select)]
#![crate_type = "lib"]

fn print() {
    println!(cfg_select! {
        unix => { "unix" }
        _ => { "not unix" }
    });
}

fn print_2() {
    println!(cfg_select! {
        unix => "unix",
        _ => "not unix",
    });
}

fn arm_rhs_expr_1() -> i32 {
    cfg_select! {
        true => 1
    }
}

fn arm_rhs_expr_2() -> i32 {
    cfg_select! {
        true => 1,
        false => 2
    }
}

fn arm_rhs_expr_3() -> i32 {
    cfg_select! {
        true => 1,
        false => 2,
        true => { 42 }
        false => -1 as i32,
        true => 2 + 2,
        false => "",
        true => if true { 42 } else { 84 }
        false => if true { 42 } else { 84 },
        true => return 42,
        false => loop {}
        true => (1, 2),
        false => (1, 2,),
        true => todo!(),
        false => println!("hello"),
    }
}

cfg_select! {
    _ => {}
    true => {}
    //~^ WARN unreachable predicate
}

cfg_select! {
    //~^ ERROR none of the predicates in this `cfg_select` evaluated to true
    false => {}
}

cfg_select! {}
//~^ ERROR none of the predicates in this `cfg_select` evaluated to true