From 42bf2af5ea1ab6e797fe2ce0abfb83e111288ded Mon Sep 17 00:00:00 2001
From: Jieyou Xu <jieyouxu@outlook.com>
Date: Thu, 19 Dec 2024 21:37:18 +0800
Subject: [PATCH 1/2] opt-dist: propagate channel info to bootstrap

---
 src/tools/opt-dist/src/tests.rs | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/tools/opt-dist/src/tests.rs b/src/tools/opt-dist/src/tests.rs
index 887055798e00a..06ed076a86437 100644
--- a/src/tools/opt-dist/src/tests.rs
+++ b/src/tools/opt-dist/src/tests.rs
@@ -25,6 +25,8 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
     let host_triple = env.host_tuple();
     let version = find_dist_version(&dist_dir)?;
 
+    let channel = version_to_channel(&version);
+
     // Extract rustc, libstd, cargo and src archives to create the optimized sysroot
     let rustc_dir = extract_dist_dir(&format!("rustc-{version}-{host_triple}"))?.join("rustc");
     let libstd_dir = extract_dist_dir(&format!("rust-std-{version}-{host_triple}"))?
@@ -61,9 +63,13 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
     assert!(llvm_config.is_file());
 
     let config_content = format!(
-        r#"profile = "user"
+        r#"
+profile = "user"
 change-id = 115898
 
+[rust]
+channel = "{channel}"
+
 [build]
 rustc = "{rustc}"
 cargo = "{cargo}"
@@ -116,3 +122,13 @@ fn find_dist_version(directory: &Utf8Path) -> anyhow::Result<String> {
         archive.strip_prefix("reproducible-artifacts-").unwrap().split_once('-').unwrap();
     Ok(version.to_string())
 }
+
+/// Roughly convert a version string (`nightly`, `beta`, or `1.XY.Z`) to channel string (`nightly`,
+/// `beta` or `stable`).
+fn version_to_channel(version_str: &str) -> &'static str {
+    match version_str {
+        "nightly" => "nightly",
+        "beta" => "beta",
+        _ => "stable",
+    }
+}

From d6ceae0fd89ad0f9e882aea1f9e92dff673fcfba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?=
 <39484203+jieyouxu@users.noreply.github.com>
Date: Tue, 10 Dec 2024 21:02:49 +0800
Subject: [PATCH 2/2] Adjust `rustc_bootstap.rs` ui test

- Fixed test name, it should've been `rustc_bootstrap.rs`, oops.
- Slightly reworded test comment to make it more clear.
---
 ...orce_stable.stderr => rustc_bootstrap.force_stable.stderr} | 0
 tests/ui/bootstrap/{rustc_bootstap.rs => rustc_bootstrap.rs}  | 4 ++--
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename tests/ui/bootstrap/{rustc_bootstap.force_stable.stderr => rustc_bootstrap.force_stable.stderr} (100%)
 rename tests/ui/bootstrap/{rustc_bootstap.rs => rustc_bootstrap.rs} (89%)

diff --git a/tests/ui/bootstrap/rustc_bootstap.force_stable.stderr b/tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr
similarity index 100%
rename from tests/ui/bootstrap/rustc_bootstap.force_stable.stderr
rename to tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr
diff --git a/tests/ui/bootstrap/rustc_bootstap.rs b/tests/ui/bootstrap/rustc_bootstrap.rs
similarity index 89%
rename from tests/ui/bootstrap/rustc_bootstap.rs
rename to tests/ui/bootstrap/rustc_bootstrap.rs
index 3d792ef4be4e5..daa28e0cdf29e 100644
--- a/tests/ui/bootstrap/rustc_bootstap.rs
+++ b/tests/ui/bootstrap/rustc_bootstrap.rs
@@ -1,5 +1,5 @@
-//! Check `RUSTC_BOOTSTRAP`'s behavior in relation to feature stability and what rustc considers
-//! itself to be (stable vs non-stable ).
+//! Check the compiler's behavior when the perma-unstable env var `RUSTC_BOOTSTRAP` is set in the
+//! environment in relation to feature stability and which channel rustc considers itself to be.
 //!
 //! `RUSTC_BOOTSTRAP` accepts:
 //!