Skip to content

Commit d8f0381

Browse files
authored
Unrolled build for rust-lang#132993
Rollup merge of rust-lang#132993 - jieyouxu:i_am_very_stable, r=chenyukang Make rustc consider itself a stable compiler when `RUSTC_BOOTSTRAP=-1` Addresses rust-lang#123404 to allow test writers to specify `//@ rustc-env:RUSTC_BOOTSTRAP=-1` to have a given rustc consider itself a stable rustc. This is only intended for testing usages. I did not use `RUSTC_BOOTSTRAP=0` because that can be confusing, i.e. one might think that means "not bootstrapping", but "forcing a given rustc to consider itself a stable compiler" is a different use case. I also added a specific test to check `RUSTC_BOOTSTRAP`'s various values and how that interacts with rustc's stability story w.r.t. features and cli flags. Noticed when trying to write a test for enabling ICE file dumping on stable. Dunno if this needs a compiler FCP or MCP, but I can file an MCP or ask someone to start an FCP if needed. Note that `RUSTC_BOOTSTRAP` is a perma-unstable env var and has no stability guarantees (heh) whatsoever. This does not affect bootstrapping because bootstrap never sets `RUSTC_BOOTSTRAP=-1`. If someone does set that when bootstrapping, it is considered PEBKAC. Accompanying dev-guide PR: rust-lang/rustc-dev-guide#2136 cc `@estebank` and `@rust-lang/wg-diagnostics` for FYI
2 parents 3fb7e44 + c130501 commit d8f0381

File tree

5 files changed

+81
-9
lines changed

5 files changed

+81
-9
lines changed

compiler/rustc_feature/src/lib.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ impl UnstableFeatures {
7474
// Returns whether `krate` should be counted as unstable
7575
let is_unstable_crate =
7676
|var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name));
77-
// `true` if we should enable unstable features for bootstrapping.
78-
let bootstrap =
79-
std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var));
80-
match (disable_unstable_features, bootstrap) {
81-
(_, true) => UnstableFeatures::Cheat,
82-
(true, _) => UnstableFeatures::Disallow,
83-
(false, _) => UnstableFeatures::Allow,
77+
78+
let bootstrap = std::env::var("RUSTC_BOOTSTRAP").ok();
79+
if let Some(val) = bootstrap.as_deref() {
80+
match val {
81+
val if val == "1" || is_unstable_crate(val) => return UnstableFeatures::Cheat,
82+
// Hypnotize ourselves so that we think we are a stable compiler and thus don't
83+
// allow any unstable features.
84+
"-1" => return UnstableFeatures::Disallow,
85+
_ => {}
86+
}
8487
}
88+
89+
if disable_unstable_features { UnstableFeatures::Disallow } else { UnstableFeatures::Allow }
8590
}
8691

8792
pub fn is_nightly_build(&self) -> bool {

compiler/rustc_feature/src/tests.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ fn rustc_bootstrap_parsing() {
1818
assert!(!is_bootstrap("x,y,z", Some("a")));
1919
assert!(!is_bootstrap("x,y,z", None));
2020

21-
// this is technically a breaking change, but there are no stability guarantees for RUSTC_BOOTSTRAP
21+
// `RUSTC_BOOTSTRAP=0` is not recognized.
2222
assert!(!is_bootstrap("0", None));
23+
24+
// `RUSTC_BOOTSTRAP=-1` is force-stable, no unstable features allowed.
25+
let is_force_stable = |krate| {
26+
std::env::set_var("RUSTC_BOOTSTRAP", "-1");
27+
matches!(UnstableFeatures::from_environment(krate), UnstableFeatures::Disallow)
28+
};
29+
assert!(is_force_stable(None));
30+
// Does not support specifying any crate.
31+
assert!(is_force_stable(Some("x")));
32+
assert!(is_force_stable(Some("x,y,z")));
2333
}

compiler/rustc_feature/src/unstable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct EnabledLangFeature {
5454
pub stable_since: Option<Symbol>,
5555
}
5656

57-
/// Information abhout an enabled library feature.
57+
/// Information about an enabled library feature.
5858
#[derive(Debug, Copy, Clone)]
5959
pub struct EnabledLibFeature {
6060
pub gate_name: Symbol,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: the option `Z` is only accepted on the nightly compiler
2+
3+
help: consider switching to a nightly toolchain: `rustup default nightly`
4+
5+
note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see <https://rust-lang.github.io/rustup/concepts/index.html>
6+
7+
note: for more information about Rust's stability policy, see <https://doc.rust-lang.org/book/appendix-07-nightly-rust.html#unstable-features>
8+
9+
error: 1 nightly option were parsed
10+

tests/ui/bootstrap/rustc_bootstap.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//! Check `RUSTC_BOOTSTRAP`'s behavior in relation to feature stability and what rustc considers
2+
//! itself to be (stable vs non-stable ).
3+
//!
4+
//! `RUSTC_BOOTSTRAP` accepts:
5+
//!
6+
//! - `1`: cheat, allow usage of unstable features even if rustc thinks it is a stable compiler.
7+
//! - `x,y,z`: comma-delimited list of crates.
8+
//! - `-1`: force rustc to think it is a stable compiler.
9+
10+
// ignore-tidy-linelength
11+
12+
//@ revisions: default_nightly cheat cheat_single_crate cheat_multi_crate force_stable invalid_zero invalid_junk
13+
//@ only-nightly
14+
15+
//@[default_nightly] unset-rustc-env:RUSTC_BOOTSTRAP
16+
//@[default_nightly] check-pass
17+
18+
// For a nightly compiler, this is same as `default_nightly` as if `RUSTC_BOOTSTRAP` was unset.
19+
//@[invalid_zero] rustc-env:RUSTC_BOOTSTRAP=0
20+
//@[invalid_zero] check-pass
21+
22+
// Invalid values are silently discarded, same as `default_nightly`, i.e. as if `RUSTC_BOOTSTRAP`
23+
// was unset.
24+
//@[invalid_junk] rustc-env:RUSTC_BOOTSTRAP=*
25+
//@[invalid_junk] check-pass
26+
27+
//@[cheat] rustc-env:RUSTC_BOOTSTRAP=1
28+
//@[cheat] check-pass
29+
30+
//@[cheat_single_crate] rustc-env:RUSTC_BOOTSTRAP=x
31+
//@[cheat_single_crate] check-pass
32+
33+
//@[cheat_multi_crate] rustc-env:RUSTC_BOOTSTRAP=x,y,z
34+
//@[cheat_multi_crate] check-pass
35+
36+
// Note: compiletest passes some `-Z` flags to the compiler for ui testing purposes, so here we
37+
// instead abuse the fact that `-Z unstable-options` is also part of rustc's stability story and is
38+
// also affected by `RUSTC_BOOTSTRAP`.
39+
//@[force_stable] rustc-env:RUSTC_BOOTSTRAP=-1
40+
//@[force_stable] compile-flags: -Z unstable-options
41+
//@[force_stable] regex-error-pattern: error: the option `Z` is only accepted on the nightly compiler
42+
43+
#![crate_type = "lib"]
44+
45+
// Note: `rustc_attrs` is a perma-unstable internal feature that is unlikely to change, which is
46+
// used as a proxy to check `RUSTC_BOOTSTRAP` versus stability checking logic.
47+
#![feature(rustc_attrs)]

0 commit comments

Comments
 (0)