diff --git a/src/conditional-compilation.md b/src/conditional-compilation.md index 7440fe0c2..bc0e7c246 100644 --- a/src/conditional-compilation.md +++ b/src/conditional-compilation.md @@ -8,6 +8,7 @@ ConfigurationPredicate -> | ConfigurationAll | ConfigurationAny | ConfigurationNot + | ConfigurationVersion | `true` | `false` @@ -23,6 +24,15 @@ ConfigurationAny -> ConfigurationNot -> `not` `(` ConfigurationPredicate `)` +ConfigurationVersion -> + `version` `(` `"` ConfigurationVersionLiteral `"` `)` + +ConfigurationVersionLiteral -> + ConfigurationVersionPart `.` ConfigurationVersionPart (`.` ConfigurationVersionPart)? + +ConfigurationVersionPart -> + (DEC_DIGIT)+ + ConfigurationPredicateList -> ConfigurationPredicate (`,` ConfigurationPredicate)* `,`? ``` @@ -55,6 +65,11 @@ 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 + the compiler targets is higher or equal to the contained version number. + It is false otherwise. + r[cfg.option-spec] _Configuration options_ are either names or key-value pairs, and are either set or unset. @@ -299,6 +314,19 @@ r[cfg.proc_macro] Set when the crate being compiled is being compiled with the `proc_macro` [crate type]. +r[cfg.version] +### `version()` + +r[cfg.version.behavior] +The `version()` predicate evaluates to true if both: + +* The version number contained inside follows the format and +* The version number contained inside is less than or equal to the version + of the language the compiler targets. + +r[cfg.version.format] +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)`. + r[cfg.panic] ### `panic` @@ -371,6 +399,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() {