Skip to content

Commit 6fa446c

Browse files
klu235ehuss
authored andcommitted
Update conditional-compilation.md
* Clarify * Reduce redundancy
1 parent 3250d84 commit 6fa446c

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

src/conditional-compilation.md

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,31 @@
2222
> _ConfigurationPredicateList_\
2323
> &nbsp;&nbsp; _ConfigurationPredicate_ (`,` _ConfigurationPredicate_)<sup>\*</sup> `,`<sup>?</sup>
2424
25-
*Conditionally compiled source code* is source code that may or may not be
26-
considered a part of the source code depending on certain conditions. <!-- This
27-
definition is sort of vacuous --> Source code can be conditionally compiled
28-
using the [attributes] [`cfg`] and [`cfg_attr`] and the built-in [`cfg` macro].
29-
These conditions are based on the target architecture of the compiled crate,
30-
arbitrary values passed to the compiler, and a few other miscellaneous things
31-
further described below in detail.
25+
*Conditionally compiled source code* is source code that is compiled only under certain conditions. Source code can be made conditionally compiled using the [`cfg`] and [`cfg_attr`] [attributes] and the built-in [`cfg` macro]. Whether to compile can depend on the target architecture of the compiled crate, arbitrary values passed to the compiler, and other things further described below.
3226

3327
Each form of conditional compilation takes a _configuration predicate_ that
3428
evaluates to true or false. The predicate is one of the following:
3529

36-
* A configuration option. It is true if the option is set and false if it is
30+
* A configuration option. The predicate is true if the option is set, and false if it is
3731
unset.
38-
* `all()` with a comma separated list of configuration predicates. It is false
39-
if at least one predicate is false. If there are no predicates, it is true.
40-
* `any()` with a comma separated list of configuration predicates. It is true
41-
if at least one predicate is true. If there are no predicates, it is false.
42-
* `not()` with a configuration predicate. It is true if its predicate is false
43-
and false if its predicate is true.
32+
* `all()` with a comma-separated list of configuration predicates. It is true precisely if all of the given predicates are true.
33+
* `any()` with a comma-separated list of configuration predicates. It is true precisely if at least one of the given predicates is true.
34+
* `not()` with a configuration predicate. It is true precisely if the given predicate is false.
4435

45-
_Configuration options_ are names and key-value pairs that are either set or
46-
unset. Names are written as a single identifier such as, for example, `unix`.
47-
Key-value pairs are written as an identifier, `=`, and then a string. For
48-
example, `target_arch = "x86_64"` is a configuration option.
36+
_Configuration options_ are either names or key-value pairs, and are either set or
37+
unset. Configuration options that are names, such as `unix`, are specified by simply writing them.
38+
Configuration options that are key-value pairs are written in the form `key = "value"`, such as `target_arch = "x86_64"`.
4939

50-
> **Note**: Whitespace around the `=` is ignored. `foo="bar"` and `foo = "bar"`
51-
> are equivalent configuration options.
40+
> **Note**: Whitespace around the `=` is ignored, so `foo="bar"` and `foo = "bar"` are equivalent.
5241
53-
Keys are not unique in the set of key-value configuration options. For example,
54-
both `feature = "std"` and `feature = "serde"` can be set at the same time.
42+
Keys do not need to be unique. For example, both `feature = "std"` and `feature = "serde"` can be set at the same time.
5543

5644
## Set Configuration Options
5745

5846
Which configuration options are set is determined statically during the
59-
compilation of the crate. Certain options are _compiler-set_ based on data
60-
about the compilation. Other options are _arbitrarily-set_, set based on input
61-
passed to the compiler outside of the code. It is not possible to set a
47+
compilation of the crate. Some options are _compiler-set_ based on data
48+
about the compilation. Other options are _arbitrarily-set_ based on input
49+
passed to the compiler outside of the code. It is impossible to set a
6250
configuration option from within the source code of the crate being compiled.
6351

6452
> **Note**: For `rustc`, arbitrary-set configuration options are set using the
@@ -70,11 +58,7 @@ configuration option from within the source code of the crate being compiled.
7058
7159
<div class="warning">
7260

73-
Warning: It is possible for arbitrarily-set configuration options to have the
74-
same value as compiler-set configuration options. For example, it is possible
75-
to do `rustc --cfg "unix" program.rs` while compiling to a Windows target, and
76-
have both `unix` and `windows` configuration options set at the same time. It
77-
is unwise to actually do this.
61+
Warning: Arbitrarily-set configuration options can clash with compiler-set configuration options. For example, it is possible to do `rustc --cfg "unix" program.rs` while compiling to a Windows target, and have both `unix` and `windows` configuration options set at the same time. Doing this would be unwise.
7862

7963
</div>
8064

@@ -266,9 +250,7 @@ Example values:
266250
<!-- should we say they're active attributes here? -->
267251

268252
The `cfg` [attribute] conditionally includes the thing it is attached to based
269-
on a configuration predicate.
270-
271-
It is written as `cfg`, `(`, a configuration predicate, and finally `)`.
253+
on the given configuration predicate (_ConfigurationPredicate_ in the syntax above).
272254

273255
If the predicate is true, the thing is rewritten to not have the `cfg` attribute
274256
on it. If the predicate is false, the thing is removed from the source code.

0 commit comments

Comments
 (0)