@@ -2114,10 +2114,15 @@ Sometimes one wants to have different compiler outputs from the same code,
2114
2114
depending on build target, such as targeted operating system, or to enable
2115
2115
release builds.
2116
2116
2117
- There are two kinds of configuration options, one that is either defined or not
2118
- (` #[cfg(foo)] ` ), and the other that contains a string that can be checked
2119
- against (` #[cfg(bar = "baz")] ` ). Currently, only compiler-defined configuration
2120
- options can have the latter form.
2117
+ Configuration options are boolean (on or off) and are named either with a
2118
+ single identifier (e.g. ` foo ` ) or an identifier and a string (e.g. ` foo = "bar" ` ;
2119
+ the quotes are required and spaces around the ` = ` are unimportant). Note that
2120
+ similarly-named options, such as ` foo ` , ` foo="bar" ` and ` foo="baz" ` may each be set
2121
+ or unset independently.
2122
+
2123
+ Configuration options are either provided by the compiler or passed in on the
2124
+ command line using ` --cfg ` (e.g. ` rustc main.rs --cfg foo --cfg 'bar="baz"' ` ).
2125
+ Rust code then checks for their presence using the ` #[cfg(...)] ` attribute:
2121
2126
2122
2127
```
2123
2128
// The function is only included in the build when compiling for OSX
@@ -2196,7 +2201,10 @@ You can also set another attribute based on a `cfg` variable with `cfg_attr`:
2196
2201
#[cfg_attr(a, b)]
2197
2202
```
2198
2203
2199
- Will be the same as ` #[b] ` if ` a ` is set by ` cfg ` , and nothing otherwise.
2204
+ This is the same as ` #[b] ` if ` a ` is set by ` cfg ` , and nothing otherwise.
2205
+
2206
+ Lastly, configuration options can be used in expressions by invoking the ` cfg! `
2207
+ macro: ` cfg!(a) ` evaluates to ` true ` if ` a ` is set, and ` false ` otherwise.
2200
2208
2201
2209
### Lint check attributes
2202
2210
0 commit comments