about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-12 11:05:40 +0000
committerbors <bors@rust-lang.org>2025-03-12 11:05:40 +0000
commit0998d4095b0f11061f78a3f9c77a87838a4c1cb7 (patch)
tree1a603248741e7e32519113137e0e50c28f8a9377
parent57a4736e9f4b7e8089b2db60583607f3b550c862 (diff)
parented5877e0ada49a1f44f60f61c032520ec92b3607 (diff)
downloadrust-0998d4095b0f11061f78a3f9c77a87838a4c1cb7.tar.gz
rust-0998d4095b0f11061f78a3f9c77a87838a4c1cb7.zip
Auto merge of #137612 - Kobzol:bootstrap-2024, r=onur-ozkan
Update bootstrap to edition 2024

The stage0 compiler now supports edition 2024, so we can update bootstrap to it. I manually reviewed all the changes from `cargo fix --edition` and reverted most of them (`if let` -> `matches` changes and two unneeded usages of `use <>`).

r? `@onur-ozkan`

try-job: dist-x86_64-msvc
-rw-r--r--src/bootstrap/Cargo.toml2
-rw-r--r--src/bootstrap/src/bin/sccache-plus-cl.rs9
-rw-r--r--src/bootstrap/src/core/build_steps/format.rs2
-rw-r--r--src/bootstrap/src/utils/cc_detect/tests.rs56
-rw-r--r--src/bootstrap/src/utils/helpers.rs2
-rw-r--r--src/bootstrap/src/utils/job.rs65
6 files changed, 83 insertions, 53 deletions
diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml
index 2c1d85b01e6..2ea2596088f 100644
--- a/src/bootstrap/Cargo.toml
+++ b/src/bootstrap/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "bootstrap"
 version = "0.0.0"
-edition = "2021"
+edition = "2024"
 build = "build.rs"
 default-run = "bootstrap"
 
diff --git a/src/bootstrap/src/bin/sccache-plus-cl.rs b/src/bootstrap/src/bin/sccache-plus-cl.rs
index 6e87d4222e8..c161d69d5f7 100644
--- a/src/bootstrap/src/bin/sccache-plus-cl.rs
+++ b/src/bootstrap/src/bin/sccache-plus-cl.rs
@@ -4,8 +4,13 @@ use std::process::{self, Command};
 fn main() {
     let target = env::var("SCCACHE_TARGET").unwrap();
     // Locate the actual compiler that we're invoking
-    env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
-    env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
+
+    // SAFETY: we're in main, there are no other threads
+    unsafe {
+        env::set_var("CC", env::var_os("SCCACHE_CC").unwrap());
+        env::set_var("CXX", env::var_os("SCCACHE_CXX").unwrap());
+    }
+
     let mut cfg = cc::Build::new();
     cfg.cargo_metadata(false)
         .out_dir("/")
diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs
index c7eafadee2d..9817e47baa1 100644
--- a/src/bootstrap/src/core/build_steps/format.rs
+++ b/src/bootstrap/src/core/build_steps/format.rs
@@ -27,7 +27,7 @@ fn rustfmt(
     rustfmt: &Path,
     paths: &[PathBuf],
     check: bool,
-) -> impl FnMut(bool) -> RustfmtStatus {
+) -> impl FnMut(bool) -> RustfmtStatus + use<> {
     let mut cmd = Command::new(rustfmt);
     // Avoid the submodule config paths from coming into play. We only allow a single global config
     // for the workspace for now.
diff --git a/src/bootstrap/src/utils/cc_detect/tests.rs b/src/bootstrap/src/utils/cc_detect/tests.rs
index 006dfe7e5d7..c97529cbe9e 100644
--- a/src/bootstrap/src/utils/cc_detect/tests.rs
+++ b/src/bootstrap/src/utils/cc_detect/tests.rs
@@ -9,20 +9,24 @@ use crate::{Build, Config, Flags};
 fn test_cc2ar_env_specific() {
     let triple = "x86_64-unknown-linux-gnu";
     let key = "AR_x86_64_unknown_linux_gnu";
-    env::set_var(key, "custom-ar");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::set_var(key, "custom-ar") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
     let result = cc2ar(cc, target, default_ar);
-    env::remove_var(key);
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var(key) };
     assert_eq!(result, Some(PathBuf::from("custom-ar")));
 }
 
 #[test]
 fn test_cc2ar_musl() {
     let triple = "x86_64-unknown-linux-musl";
-    env::remove_var("AR_x86_64_unknown_linux_musl");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_x86_64_unknown_linux_musl") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
@@ -33,8 +37,10 @@ fn test_cc2ar_musl() {
 #[test]
 fn test_cc2ar_openbsd() {
     let triple = "x86_64-unknown-openbsd";
-    env::remove_var("AR_x86_64_unknown_openbsd");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_x86_64_unknown_openbsd") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/cc");
     let default_ar = PathBuf::from("default-ar");
@@ -45,8 +51,10 @@ fn test_cc2ar_openbsd() {
 #[test]
 fn test_cc2ar_vxworks() {
     let triple = "armv7-wrs-vxworks";
-    env::remove_var("AR_armv7_wrs_vxworks");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_armv7_wrs_vxworks") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
@@ -57,8 +65,10 @@ fn test_cc2ar_vxworks() {
 #[test]
 fn test_cc2ar_nto_i586() {
     let triple = "i586-unknown-nto-something";
-    env::remove_var("AR_i586_unknown_nto_something");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_i586_unknown_nto_something") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
@@ -69,8 +79,10 @@ fn test_cc2ar_nto_i586() {
 #[test]
 fn test_cc2ar_nto_aarch64() {
     let triple = "aarch64-unknown-nto-something";
-    env::remove_var("AR_aarch64_unknown_nto_something");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_aarch64_unknown_nto_something") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
@@ -81,8 +93,10 @@ fn test_cc2ar_nto_aarch64() {
 #[test]
 fn test_cc2ar_nto_x86_64() {
     let triple = "x86_64-unknown-nto-something";
-    env::remove_var("AR_x86_64_unknown_nto_something");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_x86_64_unknown_nto_something") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
@@ -94,8 +108,10 @@ fn test_cc2ar_nto_x86_64() {
 #[should_panic(expected = "Unknown architecture, cannot determine archiver for Neutrino QNX")]
 fn test_cc2ar_nto_unknown() {
     let triple = "powerpc-unknown-nto-something";
-    env::remove_var("AR_powerpc_unknown_nto_something");
-    env::remove_var("AR");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR_powerpc_unknown_nto_something") };
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::remove_var("AR") };
     let target = TargetSelection::from_user(triple);
     let cc = Path::new("/usr/bin/clang");
     let default_ar = PathBuf::from("default-ar");
@@ -177,7 +193,8 @@ fn test_default_compiler_wasi() {
     let build = Build::new(Config { ..Config::parse(Flags::parse(&["check".to_owned()])) });
     let target = TargetSelection::from_user("wasm32-wasi");
     let wasi_sdk = PathBuf::from("/wasi-sdk");
-    env::set_var("WASI_SDK_PATH", &wasi_sdk);
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe { env::set_var("WASI_SDK_PATH", &wasi_sdk) };
     let mut cfg = cc::Build::new();
     if let Some(result) = default_compiler(&mut cfg, Language::C, target.clone(), &build) {
         let expected = {
@@ -190,7 +207,10 @@ fn test_default_compiler_wasi() {
             "default_compiler should return a compiler path for wasi target when WASI_SDK_PATH is set"
         );
     }
-    env::remove_var("WASI_SDK_PATH");
+    // SAFETY: bootstrap tests run on a single thread
+    unsafe {
+        env::remove_var("WASI_SDK_PATH");
+    }
 }
 
 #[test]
diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs
index 7ad308cd067..89d93a29acb 100644
--- a/src/bootstrap/src/utils/helpers.rs
+++ b/src/bootstrap/src/utils/helpers.rs
@@ -286,7 +286,7 @@ pub fn output(cmd: &mut Command) -> String {
 /// to finish and then return its output. This allows the spawned process
 /// to do work without immediately blocking bootstrap.
 #[track_caller]
-pub fn start_process(cmd: &mut Command) -> impl FnOnce() -> String {
+pub fn start_process(cmd: &mut Command) -> impl FnOnce() -> String + use<> {
     let child = match cmd.stderr(Stdio::inherit()).stdout(Stdio::piped()).spawn() {
         Ok(child) => child,
         Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")),
diff --git a/src/bootstrap/src/utils/job.rs b/src/bootstrap/src/utils/job.rs
index a60e889fd57..4949518de79 100644
--- a/src/bootstrap/src/utils/job.rs
+++ b/src/bootstrap/src/utils/job.rs
@@ -7,7 +7,9 @@ pub unsafe fn setup(_build: &mut crate::Build) {}
 #[cfg(all(unix, not(target_os = "haiku")))]
 pub unsafe fn setup(build: &mut crate::Build) {
     if build.config.low_priority {
-        libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
+        unsafe {
+            libc::setpriority(libc::PRIO_PGRP as _, 0, 10);
+        }
     }
 }
 
@@ -59,38 +61,41 @@ mod for_windows {
     use crate::Build;
 
     pub unsafe fn setup(build: &mut Build) {
-        // Enable the Windows Error Reporting dialog which msys disables,
-        // so we can JIT debug rustc
-        let mode = SetErrorMode(THREAD_ERROR_MODE::default());
-        let mode = THREAD_ERROR_MODE(mode);
-        SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
+        // SAFETY: pretty much everything below is unsafe
+        unsafe {
+            // Enable the Windows Error Reporting dialog which msys disables,
+            // so we can JIT debug rustc
+            let mode = SetErrorMode(THREAD_ERROR_MODE::default());
+            let mode = THREAD_ERROR_MODE(mode);
+            SetErrorMode(mode & !SEM_NOGPFAULTERRORBOX);
 
-        // Create a new job object for us to use
-        let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
+            // Create a new job object for us to use
+            let job = CreateJobObjectW(None, PCWSTR::null()).unwrap();
 
-        // Indicate that when all handles to the job object are gone that all
-        // process in the object should be killed. Note that this includes our
-        // entire process tree by default because we've added ourselves and our
-        // children will reside in the job by default.
-        let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
-        info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
-        if build.config.low_priority {
-            info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
-            info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
-        }
-        let r = SetInformationJobObject(
-            job,
-            JobObjectExtendedLimitInformation,
-            &info as *const _ as *const c_void,
-            size_of_val(&info) as u32,
-        );
-        assert!(r.is_ok(), "{}", io::Error::last_os_error());
+            // Indicate that when all handles to the job object are gone that all
+            // process in the object should be killed. Note that this includes our
+            // entire process tree by default because we've added ourselves and our
+            // children will reside in the job by default.
+            let mut info = JOBOBJECT_EXTENDED_LIMIT_INFORMATION::default();
+            info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+            if build.config.low_priority {
+                info.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_PRIORITY_CLASS;
+                info.BasicLimitInformation.PriorityClass = BELOW_NORMAL_PRIORITY_CLASS.0;
+            }
+            let r = SetInformationJobObject(
+                job,
+                JobObjectExtendedLimitInformation,
+                &info as *const _ as *const c_void,
+                size_of_val(&info) as u32,
+            );
+            assert!(r.is_ok(), "{}", io::Error::last_os_error());
 
-        // Assign our process to this job object.
-        let r = AssignProcessToJobObject(job, GetCurrentProcess());
-        if r.is_err() {
-            CloseHandle(job).ok();
-            return;
+            // Assign our process to this job object.
+            let r = AssignProcessToJobObject(job, GetCurrentProcess());
+            if r.is_err() {
+                CloseHandle(job).ok();
+                return;
+            }
         }
 
         // Note: we intentionally leak the job object handle. When our process exits