You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Translate the `-nightly` pre-release to `-incomplete
243
243
- Strip the `-beta.5` pre-release
244
244
245
-
`rust` will be specified as `--check-cfg 'cfg(rust, values(version("1.95.0")))'`
245
+
`rust` will be specified as `--check-cfg 'cfg(rust, values(since("1.95.0")))'`
246
246
(or whatever version this gets stabilized in).
247
247
248
248
This will be reported back through `--print-cfg`.
@@ -256,16 +256,17 @@ Cargo will expose `rust` in:
256
256
257
257
Clippy has a [`clippy::incompatible_msrv`](https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv) lint
258
258
which will fire whenever a standard library item is used with a `#[stable(since)]` newer than `package.rust-version`.
259
-
However, it will be perfectly reasonable to use those items when guarded by a `#[cfg(version)]`.
259
+
However, it will be perfectly reasonable to use those items when guarded by a `#[cfg(since)]`.
260
260
261
261
Clippy may wish to:
262
-
- Find a way to reduce false positives, e.g. evaluating the `cfg(version)`s that led to the item's usage or disabling the lint within `#[cfg(version)]`
263
-
- Suggest `#[cfg(version)]` in the `clippy::incompatible_msrv` diagnostic report (maybe along with offering to bump MSRV)
262
+
- Find a way to reduce false positives, e.g. evaluating the `cfg(since)`s that led to the item's usage or disabling the lint within `#[cfg(since)]`
263
+
- Suggest `#[cfg(since)]` in the `clippy::incompatible_msrv` diagnostic report (maybe along with offering to bump MSRV)
264
264
265
265
# Drawbacks
266
266
[drawbacks]: #drawbacks
267
267
268
268
People may be using `--cfg rust` already and would be broken by this change.
269
+
There are no compatibility concerns with predicate names.
269
270
270
271
This does not include a solution for adopting this within `Cargo.toml` without waiting for an MSRV bump.
271
272
@@ -281,16 +282,20 @@ Libraries could having ticking time bombs that accidentally break or have undesi
We could offer a `before` operator but that is already covered by `not(version)`.
287
+
We could offer a `before` operator but that is already covered by `not(since)`.
287
288
288
-
The `version` predicate's name doesn't convey what operation is happening and doesn't leave room for other version operators (e.g. a `before` to go with `since`).
289
-
We could call this `since`, `minimum`, or support comparison operators in the spirit of [RFC 3796](https://github.com/rust-lang/rfcs/pull/3796).
290
-
The challenge is dealing with clarity around the meaning, especially if we gain support for other data types in `cfg`, like integers, which is of interest for embedded development.
291
-
`since` would fit in with `deprecated`.
289
+
The `since` name was taken from
290
+
[rustversion](https://crates.io/crates/rustversion) and the `#[deprecated(since)]` / `#[stable(since)]` attributes.
291
+
This better conveys what operation is being performed than the original `version` name
292
+
and leaves room for related predicates like `before`.
293
+
We could also call this `minimum`, or support comparison operators in the spirit of [RFC 3796](https://github.com/rust-lang/rfcs/pull/3796).
294
+
The risk with a general word like `since` is if we gain support for other data types in cfgs, like integers for embedded development.
295
+
The name `since` might apply in some situations but not others and its unclear if we'd want to generalize it past versions.
296
+
While having a specific name avoids these concerns.
292
297
293
-
We could swap the order of parameters and make `rust` a default for the second parameter to allow `#[cfg(version("1.95"))]` as a shorthand.
298
+
We could swap the order of parameters and make `rust` a default for the second parameter to allow `#[cfg(since("1.95"))]` as a shorthand.
294
299
However, this would look confusing in Cargo and doesn't seem like its offering enough of a benefit to be worth the costs.
295
300
296
301
The `ConfigurationVersion` is sloppy with the string literal's syntax (relying on `--check-cfg`) so that
@@ -299,8 +304,8 @@ The `ConfigurationVersion` is sloppy with the string literal's syntax (relying o
299
304
300
305
If we were stricter on the syntax,
301
306
we could allow for version numbers to be directly accepted, without quotes
302
-
(e.g. `#[cfg(version(rust, 1.95.0))]`).
303
-
If we ever decided to support operators (e.g.`#[cfg(version(rust, "=1.95.0"))]`), then we'd need to decide if those also go outside the string or then require a string, being inconsistent.
307
+
(e.g. `#[cfg(since(rust, 1.95.0))]`).
308
+
If we ever decided to support operators (e.g.`#[cfg(since(rust, "=1.95.0"))]`, see `--check-cfg`), then we'd need to decide if those also go outside the string or then require a string, being inconsistent.
304
309
This would also be inconsistent with other uses of `cfg`s
305
310
*but* maybe that would just be the start to natively supporting more types in `cfg`,
306
311
like integers which are of interest to embedded folks.
@@ -309,33 +314,34 @@ like integers which are of interest to embedded folks.
309
314
310
315
The `--check-cfg` predicate and the value for `rust` ensures users get warnings about
311
316
- Invalid syntax
312
-
- Using this with versions from before its supported, e.g. `#[cfg(version(rust, "1.0.0")]`
317
+
- Using this with versions from before its supported, e.g. `#[cfg(since(rust, "1.0.0")]`
313
318
314
319
`--check-cfg` requires a SemVer version, rather than a version requirement,
315
320
in case we want the future possibility of relaxing SemVer versions
316
321
*and* we want to infer from the fields used in `--check-cfg` to specify the maximum number of fields accepted in comparisons.
317
322
318
-
We could have the `check-cfg``version` predicate only apply to the `cfg``version` predicate,
323
+
We could have the `check-cfg``since` predicate only apply to the `cfg``since` predicate,
319
324
causing `#[cfg(rust = "1.100.0")]` to warn.
320
325
However,
321
-
- the `version` predicates are a general feature intended to be used with other version numbers where exact matches may be appropriate.
326
+
- the `since` predicates are a general feature intended to be used with other version numbers where exact matches may be appropriate.
322
327
- this would get in the way of approximating the vendor version by the language version for working around compiler bugs and snapshotting of compiler output.
323
328
324
329
Possibly there could be a clippy lint specifically about `rust = "<something>"`.
325
330
Alternatively, we could try to find a way to structure `--check-cfg` to allow the person defining the `cfg` to decide whether it can be use with `=` or not.
326
-
One way of doing this is by allowing the `check-cfg``version` predicate outside of the `values` predicate,
327
-
meaning it works with the `cfg``version` predicate and not the `=` operator.
328
-
Another way would be for the `check-cfg` version predicate to never work with `=` but to instead
329
-
allow operators inside of the `cfg``version` predicate, e.g. `#[cfg(version(rust, "=1.95.0"))]`.
331
+
One way of doing this is by allowing the `check-cfg``since` predicate outside of the `values` predicate,
332
+
meaning it works with the `cfg``since` predicate and not the `=` operator.
333
+
Another way would be for the `check-cfg``since` predicate to never work with `=` but to instead
334
+
allow operators inside of the `cfg``since` predicate, e.g. `#[cfg(since(rust, "=1.95.0"))]`.
335
+
However, with the rename of the predicate from `version` to `since`, operators don't fit in as easily.
330
336
331
337
`--check-cfg` will cause the following to warn:
332
338
```rust
333
339
fnis_stderr_terminal() ->bool {
334
340
#[cfg(rust)]
335
-
#[cfg(version(rust, "1.70"))]
341
+
#[cfg(since(rust, "1.70"))]
336
342
usestd::io::IsTerminalas _;
337
343
#[cfg(rust)]
338
-
#[cfg(not(version(rust, "1.70")))]
344
+
#[cfg(not(since(rust, "1.70")))]
339
345
useis_terminal::IsTerminalas _;
340
346
#[cfg(not(rust))]
341
347
useis_terminal::IsTerminalas _;
@@ -373,21 +379,21 @@ The initial implementation treated nightlies as complete.
373
379
This was [changed to incomplete](https://github.com/rust-lang/rust/pull/72001) after
- the case of package `bleeding-edge` starting to use a new feature behind `#[cfg(version)]` and package `nightly-only` has their toolchain pinned to a nightly before the feature was stabilized (to ensure consistent behavior of unstable features), package `nightly-only` cannot add or update their dependency on `bleeding-edge` without getting a "feature gate needed" error.
382
+
- the case of package `bleeding-edge` starting to use a new feature behind `#[cfg(since)]` and package `nightly-only` has their toolchain pinned to a nightly before the feature was stabilized (to ensure consistent behavior of unstable features), package `nightly-only` cannot add or update their dependency on `bleeding-edge` without getting a "feature gate needed" error.
377
383
- bisecting nightlies.
378
384
379
385
This was [changed back to complete](https://github.com/rust-lang/rust/pull/81468) after
380
386
[some more discussion](https://github.com/rust-lang/rust/issues/64796#issuecomment-634546711).
381
387
In particular, this is important for
382
-
- keeping friction down for packages preparing for stabilized-on-nightly features as their `#[cfg(version)]`s can be inserted and "just work" which can be important for getting feedback quickly while the feature is easier to adapt to feedback that can be gained from these users
388
+
- keeping friction down for packages preparing for stabilized-on-nightly features as their `#[cfg(since)]`s can be inserted and "just work" which can be important for getting feedback quickly while the feature is easier to adapt to feedback that can be gained from these users
383
389
- releasing the package while its in this state puts it at risk to be broken if the feature is changed after stabilization
384
390
385
391
For RFC 2523, they settled on pre-releases being incomplete,
386
392
favoring maintainers to adopt stabilized-on-nightly features immediately
387
393
while letting people on pinned nightlies or bisecting nightlies to set a `-Z` to mark the version as incomplete.
388
394
389
395
In this RFC, we settled translating `-nightly` to `-incomplete` because:
390
-
- Maintainers can adopt stabilized-on-nightly features with `#[cfg(version(rust, "1.100.0-0"))]` (the lowest pre-release for `1.100.0`), keeping friction low while explicitly acknowledging that the unstable feature may change
396
+
- Maintainers can adopt stabilized-on-nightly features with `#[cfg(since(rust, "1.100.0-0"))]` (the lowest pre-release for `1.100.0`), keeping friction low while explicitly acknowledging that the unstable feature may change
391
397
- Allows build scripts to experiment with other logic without less chance of needing to invoke `rustc` (e.g. detecting nightly)
392
398
- It provides extra context when approximating the vendor version from the language version when populating build information
393
399
@@ -552,12 +558,12 @@ Haskell:
552
558
# Future possibilities
553
559
[future-possibilities]: #future-possibilities
554
560
555
-
- In the future the `--check-cfg``version()` predicate could make the minimum-version field optional,
561
+
- In the future the `--check-cfg``since()` predicate could make the minimum-version field optional,
556
562
matching all version numbers.
557
563
558
564
## Relaxing SemVer
559
565
560
-
Instead of requiring the `IDENTIFIER` in the `version` predicate to be strictly SemVer `major.minor.patch`,
566
+
Instead of requiring the `IDENTIFIER` in the `check-cfg``since` predicate to be strictly SemVer `major.minor.patch`,
561
567
we could allow abbreviated forms like `major.minor` or even `major`.
562
568
This would make the predicate more inclusive for other cases, like `edition`.
563
569
@@ -583,12 +589,12 @@ See also [`#[cfg(nightly)]`](https://rust-lang.github.io/rfcs/2523-cfg-path-vers
583
589
## `cfg_target_version`
584
590
585
591
Instead of defining a new `#[cfg]` predicate, [RFC 3750](https://github.com/rust-lang/rfcs/pull/3750)
586
-
could reuse the `#[cfg(version)]` predicate.
592
+
could reuse the `#[cfg(since)]` predicate.
587
593
588
594
As not all systems use SemVer, we can either
589
595
- Contort the version into SemVer
590
596
- This can run into problems either with having more precision (e.g. `120.0.1.10` while SemVer only allows `X.Y.Z`) or post-release versions (e.g. `1.2.0.post1` which a SemVer predicate would treat as a pre-release).
591
-
- Add an optional third field for specifying the version format (e.g. `#[cfg(version(windows, "10.0.10240", <policy-name>)]`)
597
+
- Add an optional third field for specifying the version format (e.g. `#[cfg(since(windows, "10.0.10240", <policy-name>)]`)
592
598
- Make `--check-cfg` load-bearing by having the version policy name be specified in the `--check-cfg` predicate
593
599
594
600
## Provide a way to get a `--cfg`s value
@@ -601,4 +607,4 @@ this would allow an application to approximate the vendor version `--bugreport`
601
607
602
608
As the ecosystem grows and matures,
603
609
the Rust language and standard library may not be the only dependencies users wish to support multiple versions of.
604
-
We may want to allow `#(cfg(version(serde, "1.0.900")]`.
610
+
We may want to allow `#(cfg(since(serde, "1.0.900")]`.
0 commit comments