rust-lang / rust-lang/reference
Conditional compilation makes it sound like `#[cfg(foo)]` will evaluate to `true` for `--cfg=foo="bar"` but it doesn't
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
From the Reference:
A configuration option. The predicate is true if the option is set, and false if it is unset.
And from the Reference
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 # unset
Hello from the control grup!
$ RUSTFLAGS='--cfg=foo' ./check-cfg-exists.rs # set with name
Hello from the control grup!
Hello from `foo`
$ RUSTFLAGS='--cfg=foo="value"' ./check-cfg-exists.rs # set with key-value pair
Hello from the control grup!
Hello, from `foo=value`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Reference's conditional compilation sections on cfg predicates and option syntax, then run the minimal reproduction with the shown RUSTFLAGS values. Clarify the wording so it accurately describes name and key-value configuration behavior, and verify that the examples and quoted definitions agree with the observed output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100