@@ -41,6 +41,9 @@ evaluates to true or false. The predicate is one of the following:
41
41
if at least one predicate is true. If there are no predicates, it is false.
42
42
* ` not() ` with a configuration predicate. It is true if its predicate is false
43
43
and false if its predicate is true.
44
+ * ` version() ` with a version number inside. It is true if the language version
45
+ the compiler targets is higher or equal to the contained version number.
46
+ It is false otherwise.
44
47
45
48
_ Configuration options_ are names and key-value pairs that are either set or
46
49
unset. Names are written as a single identifier such as, for example, ` unix ` .
@@ -205,6 +208,22 @@ production. For example, it controls the behavior of the standard library's
205
208
Set when the crate being compiled is being compiled with the ` proc_macro `
206
209
[ crate type] .
207
210
211
+ ## The ` version() ` predicate
212
+
213
+ The ` version() ` predicate evaluates to true if both:
214
+
215
+ * The version number contained inside follows the format and
216
+ * The version number contained inside is less than or equal to the version
217
+ of the language the compiler targets. Usually the compiler version and
218
+ language version match. So compiler version ` 1.50.0 ` targets language
219
+ ` 1.50.0 ` .
220
+
221
+ In order for it to be considered of valid format, the version number has to
222
+ follow either the ` "a.b.c" ` scheme or the ` "a.b" ` scheme, where ` a,b,c ` are
223
+ decimal integers between ` 0 ` and ` 65535 ` , inclusively. Semantically, assume ` c `
224
+ to be 0 if not present. Order wise, version numbers behave as if they were
225
+ Rust tuples ` (a,b,c) ` with ` a,b,c ` being ` u16 ` integers.
226
+
208
227
## Forms of conditional compilation
209
228
210
229
### The ` cfg ` attribute
@@ -250,6 +269,12 @@ fn on_32bit_unix() {
250
269
fn needs_not_foo () {
251
270
// ...
252
271
}
272
+
273
+ // This function is only included if the language version is newer than 1.50.0
274
+ #[cfg(version(" 1.50.0" ))]
275
+ fn needs_new_compiler () {
276
+ // ...
277
+ }
253
278
```
254
279
255
280
The ` cfg ` attribute is allowed anywhere attributes are allowed.
0 commit comments