Don't give a hard error on RUSTC_BOOTSTRAP=crate_name

This commit is contained in:
Joshua Nelson 2021-04-16 11:48:44 -04:00
parent 163097cdd9
commit 04fa2f2a3b
2 changed files with 21 additions and 1 deletions

View File

@ -589,7 +589,15 @@ impl BuildOutput {
// to set RUSTC_BOOTSTRAP.
// If this is a nightly build, setting RUSTC_BOOTSTRAP wouldn't affect the
// behavior, so still only give a warning.
if nightly_features_allowed {
// NOTE: cargo only allows nightly features on RUSTC_BOOTSTRAP=1, but we
// want setting any value of RUSTC_BOOTSTRAP to downgrade this to a warning
// (so that `RUSTC_BOOTSTRAP=pkg_name` will work)
let rustc_bootstrap_allows = |name: &str| {
std::env::var("RUSTC_BOOTSTRAP").map_or(false, |var| {
var.split(',').any(|s| s == name)
})
};
if nightly_features_allowed || rustc_bootstrap_allows(&*pkg_name) {
warnings.push(format!("Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n\
note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.",
val, whence

View File

@ -129,4 +129,16 @@ fn rustc_bootstrap() {
.masquerade_as_nightly_cargo()
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
.run();
// RUSTC_BOOTSTRAP set to the name of the crate
p.cargo("build")
.env("RUSTC_BOOTSTRAP", "foo")
.with_stderr_contains("warning: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
.run();
// RUSTC_BOOTSTRAP set to some random value
p.cargo("build")
.env("RUSTC_BOOTSTRAP", "bar")
.with_stderr_contains("error: Cannot set `RUSTC_BOOTSTRAP=1` [..]")
.with_stderr_contains("help: [..] set the environment variable `RUSTC_BOOTSTRAP=foo` [..]")
.with_status(101)
.run();
}