Skip to content

Commit 28732e0

Browse files
committed
Document #[cfg(version(...))]
1 parent 118fd1f commit 28732e0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/conditional-compilation.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ConfigurationPredicate ->
88
| ConfigurationAll
99
| ConfigurationAny
1010
| ConfigurationNot
11+
| ConfigurationVersion
1112
| `true`
1213
| `false`
1314
@@ -22,6 +23,14 @@ ConfigurationAny ->
2223
2324
ConfigurationNot ->
2425
`not` `(` ConfigurationPredicate `)`
26+
27+
ConfigurationVersion ->
28+
`version` `(` `"` ConfigurationVersionLiteral `"` `)`
29+
30+
ConfigurationVersionLiteral ->
31+
ConfigurationVersionPart `.` ConfigurationVersionPart (`.` ConfigurationVersionPart)?
32+
33+
ConfigurationVersionPart -> (DEC_DIGIT)+
2534
2635
ConfigurationPredicateList ->
2736
ConfigurationPredicate (`,` ConfigurationPredicate)* `,`?
@@ -55,6 +64,11 @@ r[cfg.predicate.not]
5564
r[cfg.predicate.literal]
5665
* `true` or `false` literals, which are always true or false respectively.
5766

67+
r[cfg.predicate.version]
68+
* `version()` with a version number inside. It is true if the language version
69+
the compiler targets is higher or equal to the contained version number.
70+
It is false otherwise.
71+
5872
r[cfg.option-spec]
5973
_Configuration options_ are either names or key-value pairs, and are either set or unset.
6074

@@ -299,6 +313,19 @@ r[cfg.proc_macro]
299313
Set when the crate being compiled is being compiled with the `proc_macro`
300314
[crate type].
301315

316+
r[cfg.version]
317+
### `version()`
318+
319+
r[cfg.version.behavior]
320+
The `version()` predicate evaluates to true if both:
321+
322+
* The version number contained inside follows the format and
323+
* The version number contained inside is less than or equal to the version
324+
of the language the compiler targets.
325+
326+
r[cfg.version.format]
327+
In order for it to be considered of valid format, the version number has to follow either the `"a.b.c"` scheme or the `"a.b"` scheme. Semantically, assume `c` to be 0 if not present. Order wise, version numbers behave as if they were Rust tuples of type `(u16, u16, u16)`.
328+
302329
r[cfg.panic]
303330
### `panic`
304331

@@ -371,6 +398,12 @@ fn needs_not_foo() {
371398
// ...
372399
}
373400

401+
// This function is only included if the language version is newer than 1.50.0
402+
#[cfg(version("1.50.0"))]
403+
fn needs_new_compiler() {
404+
// ...
405+
}
406+
374407
// This function is only included when the panic strategy is set to unwind
375408
#[cfg(panic = "unwind")]
376409
fn when_unwinding() {

0 commit comments

Comments
 (0)