Are name and key-value pair configuration options disjoint?

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

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.