You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Conditional compilation makes it sound like #[cfg(foo)] will evaluate to true for --cfg=foo="bar" but it doesn't #2004
Configuration options are either names or key-value pairs, and are either set or unset.
but rustc's behavior for #[cfg(foo)] is if its set and a name.
A minimal reproduction:
#!/usr/bin/env -S cargo +nightly -Zscript
---
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(foo,values(any()))']}
---
fn main(){println!("Hello from the control grup!");#[cfg(foo)]println!("Hello from `foo`");#[cfg(foo = "value")]println!("Hello, from `foo=value`");}
$ RUSTFLAGS='' ./check-cfg-exists.rs # unsetHello from the control grup!
$ RUSTFLAGS='--cfg=foo' ./check-cfg-exists.rs # set with nameHello from the control grup!Hello from `foo`
$ RUSTFLAGS='--cfg=foo="value"' ./check-cfg-exists.rs # set with key-value pairHello from the control grup!Hello, from `foo=value`
- A configuration option. The predicate is true if the option is set, and false if it is unset.+ A configuration option. The predicate is true if the option is set and only a name, and false if it is unset or has a value
I've not put up a PR for this yet because I feel like this might need some further investigation first.
Activity
epage commentedon Sep 17, 2025
A proposed re-wording
I've not put up a PR for this yet because I feel like this might need some further investigation first.