Skip to content

Commit c94399f

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/conditional-compilation.md

Lines changed: 34 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
@@ -23,6 +24,15 @@ ConfigurationAny ->
2324
ConfigurationNot ->
2425
`not` `(` ConfigurationPredicate `)`
2526
27+
ConfigurationVersion ->
28+
`version` `(` `"` ConfigurationVersionLiteral `"` `)`
29+
30+
ConfigurationVersionLiteral ->
31+
ConfigurationVersionPart `.` ConfigurationVersionPart (`.` ConfigurationVersionPart)?
32+
33+
ConfigurationVersionPart ->
34+
(DEC_DIGIT)+
35+
2636
ConfigurationPredicateList ->
2737
ConfigurationPredicate (`,` ConfigurationPredicate)* `,`?
2838
```
@@ -55,6 +65,11 @@ r[cfg.predicate.not]
5565
r[cfg.predicate.literal]
5666
* `true` or `false` literals, which are always true or false respectively.
5767

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

@@ -299,6 +314,19 @@ r[cfg.proc_macro]
299314
Set when the crate being compiled is being compiled with the `proc_macro`
300315
[crate type].
301316

317+
r[cfg.version]
318+
### `version()`
319+
320+
r[cfg.version.behavior]
321+
The `version()` predicate evaluates to true if both:
322+
323+
* The version number contained inside follows the format and
324+
* The version number contained inside is less than or equal to the version
325+
of the language the compiler targets.
326+
327+
r[cfg.version.format]
328+
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)`.
329+
302330
r[cfg.panic]
303331
### `panic`
304332

@@ -371,6 +399,12 @@ fn needs_not_foo() {
371399
// ...
372400
}
373401

402+
// This function is only included if the language version is at least 1.50.0
403+
#[cfg(version("1.50.0"))]
404+
fn needs_new_compiler() {
405+
// ...
406+
}
407+
374408
// This function is only included when the panic strategy is set to unwind
375409
#[cfg(panic = "unwind")]
376410
fn when_unwinding() {

0 commit comments

Comments
 (0)