Skip to content

Commit 4e2fc09

Browse files
authored
Rollup merge of rust-lang#139885 - jyn514:doc-rustc-bootstrap, r=Nadrieril
document RUSTC_BOOTSTRAP, RUSTC_OVERRIDE_VERSION_STRING, and -Z allow-features in the unstable book [rendered](https://github.com/jyn514/rust/blob/doc-rustc-bootstrap/src/doc/unstable-book/src/compiler-flags/rustc-bootstrap.md) mcp: rust-lang/compiler-team#863
2 parents 0757d24 + a114bcf commit 4e2fc09

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# `allow-features`
2+
3+
This feature is perma-unstable and has no tracking issue.
4+
5+
----
6+
7+
This flag allows limiting the features which can be enabled with `#![feature(...)]` attributes.
8+
By default, all features are allowed on nightly and no features are allowed on stable or beta (but see [`RUSTC_BOOTSTRAP`]).
9+
10+
Features are comma-separated, for example `-Z allow-features=ffi_pure,f16`.
11+
If the flag is present, any feature listed will be allowed and any feature not listed will be disallowed.
12+
Any unrecognized feature is ignored.
13+
14+
[`RUSTC_BOOTSTRAP`]: ./rustc-bootstrap.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# `RUSTC_BOOTSTRAP`
2+
3+
This feature is perma-unstable and has no tracking issue.
4+
5+
----
6+
7+
The `RUSTC_BOOTSTRAP` environment variable tells rustc to act as if it is a nightly compiler;
8+
in particular, it allows `#![feature(...)]` attributes and `-Z` flags even on the stable release channel.
9+
10+
Setting `RUSTC_BOOTSTRAP=1` instructs rustc to enable this for all crates.
11+
Setting `RUSTC_BOOTSTRAP=crate_name` instructs rustc to only apply this to crates named `crate_name`.
12+
Setting `RUSTC_BOOTSTRAP=-1` instructs rustc to act as if it is a stable compiler, even on the nightly release channel.
13+
Cargo disallows setting `cargo::rustc-env=RUSTC_BOOTSTRAP` in build scripts.
14+
Build systems can limit the features they enable with [`-Z allow-features=feature1,feature2`][Z-allow-features].
15+
Crates can fully opt out of unstable features by using [`#![forbid(unstable_features)]`][unstable-features] at the crate root (or any other way of enabling lints, such as `-F unstable-features`).
16+
17+
[Z-allow-features]: ./allow-features.html
18+
[unstable-features]: ../../rustc/lints/listing/allowed-by-default.html#unstable-features
19+
20+
## Why does this environment variable exist?
21+
22+
`RUSTC_BOOTSTRAP`, as the name suggests, is used for bootstrapping the compiler from an earlier version.
23+
In particular, nightly is built with beta, and beta is built with stable.
24+
Since the standard library and compiler both use unstable features, `RUSTC_BOOTSTRAP` is required so that we can use the previous version to build them.
25+
26+
## Why is this environment variable so easy to use for people not in the rust project?
27+
28+
Originally, `RUSTC_BOOTSTRAP` required passing in a hash of the previous compiler version, to discourage using it for any purpose other than bootstrapping.
29+
That constraint was later relaxed; see <https://github.com/rust-lang/rust/issues/36548> for the discussion that happened at that time.
30+
31+
People have at various times proposed re-adding the technical constraints.
32+
However, doing so is extremely disruptive for several major projects that we very much want to keep using the latest stable toolchain version, such as Firefox, Rust for Linux, and Chromium.
33+
We continue to allow `RUSTC_BOOTSTRAP` until we can come up with an alternative that does not disrupt our largest constituents.
34+
35+
## Stability policy
36+
37+
Despite being usable on stable, this is an unstable feature.
38+
Like any other unstable feature, we reserve the right to change or remove this feature in the future, as well as any other unstable feature that it enables.
39+
Using this feature opts you out of the normal stability/backwards compatibility guarantee of stable.
40+
41+
Although we do not take technical measures to prevent it from being used, we strongly discourage using this feature.
42+
If at all possible, please contribute to stabilizing the features you care about instead of bypassing the Rust project's stability policy.
43+
44+
For library crates, we especially discourage the use of this feature.
45+
The crates depending on you do not know that you use this feature, have little recourse if it breaks, and can be used in contexts that are hard to predict.
46+
47+
For libraries that do use this feature, please document the versions you support (including a *maximum* as well as minimum version), and a mechanism to disable it.
48+
If you do not have a mechanism to disable the use of `RUSTC_BOOTSTRAP`, consider removing its use altogether, such that people can only use your library if they are already using a nightly toolchain.
49+
This leaves the choice of whether to opt-out of Rust's stability guarantees up to the end user building their code.
50+
51+
## History
52+
53+
- [Allowed without a hash](https://github.com/rust-lang/rust/pull/37265) ([discussion](https://github.com/rust-lang/rust/issues/36548))
54+
- [Extended to crate names](https://github.com/rust-lang/rust/pull/77802) ([discussion](https://github.com/rust-lang/cargo/issues/7088))
55+
- [Disallowed for build scripts](https://github.com/rust-lang/cargo/pull/9181) ([discussion](https://github.com/rust-lang/compiler-team/issues/350))
56+
- [Extended to emulate stable](https://github.com/rust-lang/rust/pull/132993) ([discussion](https://github.com/rust-lang/rust/issues/123404))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# `RUSTC_OVERRIDE_VERSION_STRING`
2+
3+
This feature is perma-unstable and has no tracking issue.
4+
5+
----
6+
7+
The `RUSTC_OVERRIDE_VERSION_STRING` environment variable overrides the version reported by `rustc --version`. For example:
8+
9+
```console
10+
$ rustc --version
11+
rustc 1.87.0-nightly (43f0014ef 2025-03-25)
12+
$ env RUSTC_OVERRIDE_VERSION_STRING=1.81.0-nightly rustc --version
13+
rustc 1.81.0-nightly
14+
```
15+
16+
Note that the version string is completely overwritten; i.e. rustc discards commit hash and commit date information unless it is explicitly included in the environment variable. The string only applies to the "release" part of the version; for example:
17+
```console
18+
$ RUSTC_OVERRIDE_VERSION_STRING="1.81.0-nightly (aaaaaaaaa 2025-03-22)" rustc -vV
19+
rustc 1.81.0-nightly (aaaaaaaaa 2025-03-22)
20+
binary: rustc
21+
commit-hash: 43f0014ef0f242418674f49052ed39b70f73bc1c
22+
commit-date: 2025-03-25
23+
host: x86_64-unknown-linux-gnu
24+
release: 1.81.0-nightly (aaaaaaaaa 2025-03-22)
25+
LLVM version: 20.1.1
26+
```
27+
28+
Note here that `commit-hash` and `commit-date` do not match the values in the string, and `release` includes the fake hash and date.
29+
30+
This variable has no effect on whether or not unstable features are allowed to be used. It only affects the output of `--version`.
31+
32+
## Why does this environment variable exist?
33+
34+
Various library crates have incomplete or incorrect feature detection.
35+
This environment variable allows bisecting crates that do incorrect detection with `version_check::supports_feature`.
36+
37+
This is not intended to be used for any other case (and, except for bisection, is not particularly useful).
38+
39+
See <https://github.com/rust-lang/rust/pull/124339> for further discussion.

0 commit comments

Comments
 (0)