Add RUSTC_BOOTSTRAP=-1 to make rustc pretend as stable compiler

This commit is contained in:
Jieyou Xu 2024-11-13 17:55:25 +08:00
parent 46e8d20301
commit 202caa7c57
3 changed files with 24 additions and 9 deletions

View File

@ -74,14 +74,19 @@ impl UnstableFeatures {
// Returns whether `krate` should be counted as unstable // Returns whether `krate` should be counted as unstable
let is_unstable_crate = let is_unstable_crate =
|var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name)); |var: &str| krate.is_some_and(|name| var.split(',').any(|new_krate| new_krate == name));
// `true` if we should enable unstable features for bootstrapping.
let bootstrap = let bootstrap = std::env::var("RUSTC_BOOTSTRAP").ok();
std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var)); if let Some(val) = bootstrap.as_deref() {
match (disable_unstable_features, bootstrap) { match val {
(_, true) => UnstableFeatures::Cheat, val if val == "1" || is_unstable_crate(val) => return UnstableFeatures::Cheat,
(true, _) => UnstableFeatures::Disallow, // Hypnotize ourselves so that we think we are a stable compiler and thus don't
(false, _) => UnstableFeatures::Allow, // allow any unstable features.
"-1" => return UnstableFeatures::Disallow,
_ => {}
}
} }
if disable_unstable_features { UnstableFeatures::Disallow } else { UnstableFeatures::Allow }
} }
pub fn is_nightly_build(&self) -> bool { pub fn is_nightly_build(&self) -> bool {

View File

@ -18,6 +18,16 @@ fn rustc_bootstrap_parsing() {
assert!(!is_bootstrap("x,y,z", Some("a"))); assert!(!is_bootstrap("x,y,z", Some("a")));
assert!(!is_bootstrap("x,y,z", None)); assert!(!is_bootstrap("x,y,z", None));
// this is technically a breaking change, but there are no stability guarantees for RUSTC_BOOTSTRAP // `RUSTC_BOOTSTRAP=0` is not recognized.
assert!(!is_bootstrap("0", None)); assert!(!is_bootstrap("0", None));
// `RUSTC_BOOTSTRAP=-1` is force-stable, no unstable features allowed.
let is_force_stable = |krate| {
std::env::set_var("RUSTC_BOOTSTRAP", "-1");
matches!(UnstableFeatures::from_environment(krate), UnstableFeatures::Disallow)
};
assert!(is_force_stable(None));
// Does not support specifying any crate.
assert!(is_force_stable(Some("x")));
assert!(is_force_stable(Some("x,y,z")));
} }

View File

@ -54,7 +54,7 @@ pub struct EnabledLangFeature {
pub stable_since: Option<Symbol>, pub stable_since: Option<Symbol>,
} }
/// Information abhout an enabled library feature. /// Information about an enabled library feature.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct EnabledLibFeature { pub struct EnabledLibFeature {
pub gate_name: Symbol, pub gate_name: Symbol,