Skip to content

Commit e1803db

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

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/conditional-compilation.md

Lines changed: 28 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,9 @@ ConfigurationAny ->
2324
ConfigurationNot ->
2425
`not` `(` ConfigurationPredicate `)`
2526
27+
ConfigurationVersion ->
28+
`version` `(` ( STRING_LITERAL | RAW_STRING_LITERAL ) `)`
29+
2630
ConfigurationPredicateList ->
2731
ConfigurationPredicate (`,` ConfigurationPredicate)* `,`?
2832
```
@@ -55,6 +59,11 @@ r[cfg.predicate.not]
5559
r[cfg.predicate.literal]
5660
* `true` or `false` literals, which are always true or false respectively.
5761

62+
r[cfg.predicate.version]
63+
* `version()` with a version number inside. It is true if the language version
64+
the compiler targets is higher or equal to the contained version number.
65+
It is false otherwise.
66+
5867
r[cfg.option-spec]
5968
_Configuration options_ are either names or key-value pairs, and are either set or unset.
6069

@@ -299,6 +308,19 @@ r[cfg.proc_macro]
299308
Set when the crate being compiled is being compiled with the `proc_macro`
300309
[crate type].
301310

311+
r[cfg.version]
312+
### `version()`
313+
314+
r[cfg.version.behavior]
315+
The `version()` predicate evaluates to true if both:
316+
317+
* The version number contained inside follows the format and
318+
* The version number contained inside is less than or equal to the version
319+
of the language the compiler targets.
320+
321+
r[cfg.version.format]
322+
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)`.
323+
302324
r[cfg.panic]
303325
### `panic`
304326

@@ -371,6 +393,12 @@ fn needs_not_foo() {
371393
// ...
372394
}
373395

396+
// This function is only included if the language version is at least 1.50.0
397+
#[cfg(version("1.50.0"))]
398+
fn needs_new_compiler() {
399+
// ...
400+
}
401+
374402
// This function is only included when the panic strategy is set to unwind
375403
#[cfg(panic = "unwind")]
376404
fn when_unwinding() {

0 commit comments

Comments
 (0)