Skip to content

Document #[cfg(version(...))] #1828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/conditional-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ConfigurationPredicate ->
| ConfigurationAll
| ConfigurationAny
| ConfigurationNot
| ConfigurationVersion
| `true`
| `false`

Expand All @@ -23,6 +24,9 @@ ConfigurationAny ->
ConfigurationNot ->
`not` `(` ConfigurationPredicate `)`

ConfigurationVersion ->
`version` `(` ( STRING_LITERAL | RAW_STRING_LITERAL ) `)`

ConfigurationPredicateList ->
ConfigurationPredicate (`,` ConfigurationPredicate)* `,`?
```
Expand Down Expand Up @@ -55,6 +59,16 @@ r[cfg.predicate.not]
r[cfg.predicate.literal]
* `true` or `false` literals, which are always true or false respectively.

r[cfg.predicate.version]
* `version()` with a version number inside. It is true if the language version
Comment on lines +62 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we merge cfg.version into this section so that it isn't described in two places?

the compiler targets is higher or equal to the contained version number. It is false otherwise.

r[cfg.predicate.version.syntax]
The specified version 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)`.

r[cfg.predicate.version.reserved]
Invalid version literals will eval to false. This includes tuples with components that can't be represented as `u16`.

r[cfg.option-spec]
_Configuration options_ are either names or key-value pairs, and are either set or unset.

Expand Down Expand Up @@ -371,6 +385,12 @@ fn needs_not_foo() {
// ...
}

// This function is only included if the language version is at least 1.50.0
#[cfg(version("1.50.0"))]
fn needs_new_compiler() {
// ...
}

// This function is only included when the panic strategy is set to unwind
#[cfg(panic = "unwind")]
fn when_unwinding() {
Expand Down
Loading