diff --git a/library/test/build.rs b/library/test/build.rs new file mode 100644 index 000000000000..a2bc8936b519 --- /dev/null +++ b/library/test/build.rs @@ -0,0 +1,11 @@ +fn main() { + println!("cargo:rustc-check-cfg=cfg(enable_unstable_features)"); + + let rustc = std::env::var("RUSTC").unwrap_or_else(|_| "rustc".into()); + let version = std::process::Command::new(rustc).arg("-vV").output().unwrap(); + let stdout = String::from_utf8(version.stdout).unwrap(); + + if stdout.contains("nightly") || stdout.contains("dev") { + println!("cargo:rustc-cfg=enable_unstable_features"); + } +} diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 35291cc15c91..172785936b20 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -314,15 +314,14 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes { Ok(test_opts) } -// FIXME: Copied from librustc_ast until linkage errors are resolved. Issue #47566 fn is_nightly() -> bool { - // Whether this is a feature-staged build, i.e., on the beta or stable channel - let disable_unstable_features = - option_env!("CFG_DISABLE_UNSTABLE_FEATURES").map(|s| s != "0").unwrap_or(false); - // Whether we should enable unstable features for bootstrapping + // Whether the current rustc version should allow unstable features + let enable_unstable_features = cfg!(enable_unstable_features); + + // The runtime override for unstable features let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok(); - bootstrap || !disable_unstable_features + bootstrap || enable_unstable_features } // Gets the CLI options associated with `report-time` feature. diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 7107140e1511..405ab9f6eaa2 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -626,12 +626,6 @@ pub fn std_cargo( CompilerBuiltins::BuildRustOnly => "", }; - // `libtest` uses this to know whether or not to support - // `-Zunstable-options`. - if !builder.unstable_features() { - cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1"); - } - for krate in crates { cargo.args(["-p", krate]); }