Configuration options are names and key-value pairs that are either set or unset. Names are written as a single identifier such as, for example,
unix
. Key-value pairs are written as an identifier,=
, and then a string. For example,target_arch = "x86_64"
is a configuration option.
Question is whether names and key-value pairs are always disjoint. If so, users can never satisfy a name condition using a key-value pair condition (for example with an empty value) by mistake, and vice versa. My experimental code suggests they are disjoint, but I can't find a definitive answer in the reference.
#[cfg(foo)]
fn fn_foo() {
println!("foo");
}
#[cfg(foo = "bar")]
fn fn_foo_bar() {
println!("foo_bar");
}
#[cfg(foo = "baz")]
fn fn_foo_baz() {
println!("foo_baz");
}
fn main() {
fn_foo();
fn_foo_bar();
fn_foo_baz();
}
This compiles:
rustc --cfg 'foo' --cfg 'foo="bar"' --cfg 'foo="baz"' main.rs