Skip to content

Commit 56ddfc3

Browse files
committed
fix(ref): Nightly and beta are incomplete
1 parent 3f765c1 commit 56ddfc3

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

text/3857-cfg-version.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,6 @@ However, this would produce an `unexpected_cfgs` lint and you would need to add
183183
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust)'] }
184184
```
185185

186-
Say you were wanting to test out `#[must_use]` after it got stabilized on nightly to provide feedback and to be ready for when it hits stable,
187-
you would instead use `"1.27.0-0"` to match all pre-release versions of 1.27.0:
188-
```rust
189-
#[cfg_attr(since(rust, "1.27.0-0"), must_use)]
190-
fn double(x: i32) -> i32 {
191-
2 * x
192-
}
193-
194-
fn main() {
195-
double(4);
196-
// warning: unused return value of `double` which must be used
197-
// ^--- This warning only happens if we are on Rust >= 1.27.
198-
}
199-
```
200-
201186
# Reference-level explanation
202187
[reference-level-explanation]: #reference-level-explanation
203188

@@ -261,7 +246,6 @@ So given `--check-cfg 'cfg(foo, values(since("1.95.0")))'`,
261246
-`#[cfg(since(foo, "1.100.0"))]`
262247
-`#[cfg(since(foo, "3.0.0"))]`
263248
-`#[cfg(since(foo, "1.95"))]`
264-
- ⚠️ `#[cfg(since(foo, "1.95.0-0"))]`: matches a superset of `--check-cfg`
265249
- ⚠️ `#[cfg(since(foo, "1.90.0"))]`: matches a superset of `--check-cfg`
266250
- ⚠️ `#[cfg(since(foo, "1"))]`: matches a superset of `--check-cfg`
267251
- ⚠️ `#[cfg(since(foo, "bar"))]`: invalid string literal syntax
@@ -271,9 +255,10 @@ So given `--check-cfg 'cfg(foo, values(since("1.95.0")))'`,
271255
A new built-in cfg `--cfg=rust --cfg=rust="<version>"` will be added by the compiler
272256
that specifies the language version.
273257
This will be the version of `rustc` with the behavior for pre-release versions being unspecified.
274-
We expect rustc to:
275-
- Translate the `-nightly` pre-release to `-incomplete`
276-
- Strip the `-beta.5` pre-release
258+
We expect rustc to treat beta and nightly versions as an "incomplete" implementation of that language version,
259+
reporting some number less than the current nightly.
260+
We could either track the latest patch release at the time of the nightly, assume `x.y.0`, or assume `x.y.99`.
261+
The compiler may choose to offer an unstable flag to mark a nightly as "complete" to allow for testing of features with `since`.
277262

278263
`rust` will be specified as `--check-cfg 'cfg(rust, values(since("1.95.0")))'`
279264
(or whatever version this gets stabilized in).
@@ -517,7 +502,7 @@ For RFC 2523, they settled on pre-releases being incomplete,
517502
favoring maintainers to adopt stabilized-on-nightly features immediately
518503
while letting people on pinned nightlies or bisecting nightlies to set a `-Z` to mark the version as incomplete.
519504

520-
In this RFC, we settled on translating `-nightly` to `-incomplete` because:
505+
Originally, this RFC chose to translate `-nightly` to `-incomplete` because:
521506
- 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
522507
- `-0` is recommended over `-incomplete` or any other value as the exact pre-release value is unspecified.
523508
- Allows build scripts to experiment with other logic when approximating the vendor version from the language version with less of a chance of needing to invoke `rustc` (e.g. detecting nightly)
@@ -531,6 +516,9 @@ As for differentiating between nightlies,
531516
that corresponds more to the vendor version than the language version,
532517
so we do not include that information.
533518

519+
However, we've decided to punt on the question of nightlies to reduce the scope of this RFC
520+
and out of concern for published packages using unstable features that will automatically get enabled somehow.
521+
534522
## Alternative designs
535523

536524
### `cfg(rust >= "1.95")`
@@ -874,6 +862,31 @@ We could always relax this incrementally, e.g.
874862
- `BuildMetadata` for dependency versions
875863
- Whatever `target_version` requires
876864

865+
## Incomplete language versions
866+
867+
Rustc could indicate that it implements an incomplete version of the compiler by having an `-incomplete` pre-release field.
868+
This would be used for nightlies and there would be a question of whether beta should be incomplete or not.
869+
870+
This can be done later as its unstable.
871+
872+
A guide-level explanation would be:
873+
874+
> Say you were wanting to test out `#[must_use]` after it got stabilized on nightly to provide feedback and to be ready
875+
> for when it hits stable,
876+
> you would instead use `"1.27.0-0"` to match all pre-release versions of 1.27.0:
877+
> ```rust
878+
> #[cfg_attr(since(rust, "1.27.0-0"), must_use)]
879+
> fn double(x: i32) -> i32 {
880+
> 2 * x
881+
> }
882+
>
883+
> fn main() {
884+
> double(4);
885+
> // warning: unused return value of `double` which must be used
886+
> // ^--- This warning only happens if we are on Rust >= 1.27.
887+
> }
888+
> ```
889+
877890
## `--cfg edition`
878891
879892
In adding a `cfg` for the Edition, we could model it as either:

0 commit comments

Comments
 (0)