diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index 8b28105abe5ed..fab7f2098ea1c 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -22,6 +22,15 @@ pub fn bare_rustc() -> Rustc { Rustc::bare() } +/// Construct a plain `rustc` invocation with no flags set that behaves like a stable compiler, +/// i.e. rejects unstable flags. +/// Note that [`set_host_compiler_dylib_path`] still presets the environment variable +/// `HOST_RUSTC_DYLIB_PATH` by default. +#[track_caller] +pub fn stable_bare_rustc() -> Rustc { + Rustc::bare_stable() +} + /// Construct a `rustc` invocation for building `minicore`. /// /// This function: @@ -76,9 +85,6 @@ pub fn rustc_path() -> String { fn setup_common() -> Command { let mut cmd = Command::new(rustc_path()); set_host_compiler_dylib_path(&mut cmd); - if let Ok(codegen_backend) = std::env::var("RUSTC_CODEGEN_BACKEND") { - cmd.arg(format!("-Zcodegen-backend={codegen_backend}")); - } cmd } @@ -100,6 +106,10 @@ impl Rustc { cmd.arg("-Ctarget-feature=-crt-static"); } + if let Ok(codegen_backend) = std::env::var("RUSTC_CODEGEN_BACKEND") { + cmd.arg(format!("-Zcodegen-backend={codegen_backend}")); + } + // Automatically default to cross-compilation Self { cmd, target: Some(target()) } } @@ -111,6 +121,14 @@ impl Rustc { Self { cmd, target: None } } + /// Construct a bare `rustc` invocation with no flags set that acts like a stable compiler. + #[track_caller] + pub fn bare_stable() -> Self { + let mut cmd = setup_common(); + cmd.env("RUSTC_BOOTSTRAP", "-1"); + Self { cmd, target: None } + } + // Argument provider methods /// Configure the compilation environment. diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index d3c2115e745e0..b9717bda1e2c7 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -79,7 +79,9 @@ pub use crate::external_deps::llvm::{ llvm_readobj, }; pub use crate::external_deps::python::python_command; -pub use crate::external_deps::rustc::{self, Rustc, bare_rustc, rustc, rustc_minicore, rustc_path}; +pub use crate::external_deps::rustc::{ + self, Rustc, bare_rustc, rustc, rustc_minicore, rustc_path, stable_bare_rustc, +}; pub use crate::external_deps::rustdoc::{Rustdoc, bare_rustdoc, rustdoc}; // Path-related helpers. pub use crate::path_helpers::{ diff --git a/tests/run-make/const-destruct-stable-toolchain/rmake.rs b/tests/run-make/const-destruct-stable-toolchain/rmake.rs index 0f36d71f2c874..c4990582d40ba 100644 --- a/tests/run-make/const-destruct-stable-toolchain/rmake.rs +++ b/tests/run-make/const-destruct-stable-toolchain/rmake.rs @@ -1,17 +1,15 @@ //@ needs-target-std -// FIXME: Once GCC backend is fixed, remove this `ignore-backends`. //@ ignore-backends: gcc // Test that the suggestion to constrain a type parameter that is dropped in a const // function with a `[const] Destruct` bound is only offered on nightly, since the bound // requires an unstable feature. -use run_make_support::{diff, rustc}; +use run_make_support::{diff, rustc, stable_bare_rustc}; fn main() { - let out = rustc() + let out = stable_bare_rustc() .input("const-drop.rs") - .env("RUSTC_BOOTSTRAP", "-1") .run_fail() .assert_stderr_not_contains("consider restricting type parameter `T`") .stderr_utf8(); diff --git a/tests/run-make/const-trait-stable-toolchain/rmake.rs b/tests/run-make/const-trait-stable-toolchain/rmake.rs index e2ec58f03db19..c778873463063 100644 --- a/tests/run-make/const-trait-stable-toolchain/rmake.rs +++ b/tests/run-make/const-trait-stable-toolchain/rmake.rs @@ -1,16 +1,14 @@ //@ needs-target-std -// FIXME: Once GCC backend is fixed, remove this `ignore-backends`. //@ ignore-backends: gcc // Test output of const super trait errors in both stable and nightly. // We don't want to provide suggestions on stable that only make sense in nightly. -use run_make_support::{diff, rustc}; +use run_make_support::{diff, rustc, stable_bare_rustc}; fn main() { - let out = rustc() + let out = stable_bare_rustc() .input("const-super-trait.rs") - .env("RUSTC_BOOTSTRAP", "-1") .cfg("feature_enabled") .run_fail() .assert_stderr_not_contains("as `const` to allow it to have `const` implementations") @@ -35,9 +33,8 @@ fn main() { .expected_file("const-super-trait-nightly-enabled.stderr") .actual_text("(rustc)", &out) .run(); - let out = rustc() + let out = stable_bare_rustc() .input("const-super-trait.rs") - .env("RUSTC_BOOTSTRAP", "-1") .run_fail() .assert_stderr_not_contains("enable `#![feature(const_trait_impl)]` in your crate and mark") .assert_stderr_not_contains("as `const` to allow it to have `const` implementations") diff --git a/tests/run-make/issue-149402-suggest-unresolve/rmake.rs b/tests/run-make/issue-149402-suggest-unresolve/rmake.rs index 78348b914d1e6..a8d92606ee893 100644 --- a/tests/run-make/issue-149402-suggest-unresolve/rmake.rs +++ b/tests/run-make/issue-149402-suggest-unresolve/rmake.rs @@ -4,18 +4,12 @@ //! //@ only-nightly //@ needs-target-std -// FIXME: Once GCC backend is fixed, remove this `ignore-backends`. //@ ignore-backends: gcc -use run_make_support::{diff, rustc, similar}; +use run_make_support::{diff, rustc, similar, stable_bare_rustc}; fn main() { - let stable_like = rustc() - .env("RUSTC_BOOTSTRAP", "-1") - .edition("2024") - .input("foo.rs") - .run_fail() - .stderr_utf8(); + let stable_like = stable_bare_rustc().edition("2024").input("foo.rs").run_fail().stderr_utf8(); assert!(!stable_like.contains("CoroutineState::Complete")); diff().expected_file("stable.err").actual_text("stable_like", &stable_like).run(); diff --git a/tests/run-make/missing-unstable-trait-bound/rmake.rs b/tests/run-make/missing-unstable-trait-bound/rmake.rs index 753f4abcf32fd..52a011285c95c 100644 --- a/tests/run-make/missing-unstable-trait-bound/rmake.rs +++ b/tests/run-make/missing-unstable-trait-bound/rmake.rs @@ -2,17 +2,15 @@ //@ ignore-wasm32 //@ ignore-wasm64 // ignore-tidy-linelength -// FIXME: Once GCC backend is fixed, remove this `ignore-backends`. //@ ignore-backends: gcc // Ensure that on stable we don't suggest restricting with an unsafe trait and we continue // mentioning the rest of the obligation chain. -use run_make_support::{diff, rustc}; +use run_make_support::{diff, stable_bare_rustc}; fn main() { - let out = rustc() - .env("RUSTC_BOOTSTRAP", "-1") + let out = stable_bare_rustc() .input("missing-bound.rs") .run_fail() .assert_stderr_not_contains("help: consider restricting type parameter `T`") diff --git a/tests/run-make/print-request-help-stable-unstable/rmake.rs b/tests/run-make/print-request-help-stable-unstable/rmake.rs index 62cf0483f320d..01572a5aad942 100644 --- a/tests/run-make/print-request-help-stable-unstable/rmake.rs +++ b/tests/run-make/print-request-help-stable-unstable/rmake.rs @@ -2,18 +2,13 @@ //! //! Issue: -// FIXME: Once GCC backend is fixed, remove this `ignore-backends`. //@ ignore-backends: gcc -use run_make_support::{diff, rustc, similar}; +use run_make_support::{diff, rustc, similar, stable_bare_rustc}; fn main() { - let stable_invalid_print_request_help = rustc() - .env("RUSTC_BOOTSTRAP", "-1") - .cfg("force_stable") - .print("xxx") - .run_fail() - .stderr_utf8(); + let stable_invalid_print_request_help = + stable_bare_rustc().print("xxx").run_fail().stderr_utf8(); assert!(!stable_invalid_print_request_help.contains("all-target-specs-json")); diff() .expected_file("stable-invalid-print-request-help.err")