Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
}

Expand All @@ -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()) }
}
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
6 changes: 2 additions & 4 deletions tests/run-make/const-destruct-stable-toolchain/rmake.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
9 changes: 3 additions & 6 deletions tests/run-make/const-trait-stable-toolchain/rmake.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand Down
10 changes: 2 additions & 8 deletions tests/run-make/issue-149402-suggest-unresolve/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions tests/run-make/missing-unstable-trait-bound/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`")
Expand Down
11 changes: 3 additions & 8 deletions tests/run-make/print-request-help-stable-unstable/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@
//!
//! Issue: <https://github.com/rust-lang/rust/issues/138698>

// 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")
Expand Down
Loading