Rollup merge of #132993 - jieyouxu:i_am_very_stable, r=chenyukang
Make rustc consider itself a stable compiler when `RUSTC_BOOTSTRAP=-1` Addresses https://github.com/rust-lang/rust/issues/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: https://github.com/rust-lang/rustc-dev-guide/pull/2136 cc `@estebank` and `@rust-lang/wg-diagnostics` for FYI
This commit is contained in:
@@ -74,14 +74,19 @@ impl UnstableFeatures {
|
||||
// Returns whether `krate` should be counted as unstable
|
||||
let is_unstable_crate =
|
||||
|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 =
|
||||
std::env::var("RUSTC_BOOTSTRAP").is_ok_and(|var| var == "1" || is_unstable_crate(&var));
|
||||
match (disable_unstable_features, bootstrap) {
|
||||
(_, true) => UnstableFeatures::Cheat,
|
||||
(true, _) => UnstableFeatures::Disallow,
|
||||
(false, _) => UnstableFeatures::Allow,
|
||||
|
||||
let bootstrap = std::env::var("RUSTC_BOOTSTRAP").ok();
|
||||
if let Some(val) = bootstrap.as_deref() {
|
||||
match val {
|
||||
val if val == "1" || is_unstable_crate(val) => return UnstableFeatures::Cheat,
|
||||
// Hypnotize ourselves so that we think we are a stable compiler and thus don't
|
||||
// allow any unstable features.
|
||||
"-1" => return UnstableFeatures::Disallow,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if disable_unstable_features { UnstableFeatures::Disallow } else { UnstableFeatures::Allow }
|
||||
}
|
||||
|
||||
pub fn is_nightly_build(&self) -> bool {
|
||||
|
||||
@@ -18,6 +18,16 @@ fn rustc_bootstrap_parsing() {
|
||||
assert!(!is_bootstrap("x,y,z", Some("a")));
|
||||
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));
|
||||
|
||||
// `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")));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ pub struct EnabledLangFeature {
|
||||
pub stable_since: Option<Symbol>,
|
||||
}
|
||||
|
||||
/// Information abhout an enabled library feature.
|
||||
/// Information about an enabled library feature.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EnabledLibFeature {
|
||||
pub gate_name: Symbol,
|
||||
|
||||
Reference in New Issue
Block a user