mirror of
https://github.com/rust-lang/rust.git
synced 2025-09-28 21:55:31 +00:00

When operating on expressions, `cfg_select!` can now handle expressions without braces. (It still requires braces for other things, such as items.) Expand the test coverage and documentation accordingly.
63 lines
1.1 KiB
Rust
63 lines
1.1 KiB
Rust
#![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
|