]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/format.rs
Rollup merge of #83327 - tmiasko:visit-lhs, r=davidtwco
[rust.git] / src / bootstrap / format.rs
index 40043c6e31ad2f85a983592a754b25cbd80066be..d21e3408144fea607c598ea6695d479c58e28539 100644 (file)
@@ -8,7 +8,7 @@
 use std::process::{Command, Stdio};
 use std::sync::mpsc::SyncSender;
 
-fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> Box<impl FnMut()> {
+fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl FnMut() {
     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
@@ -22,8 +22,8 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> Box<im
     cmd.args(paths);
     let cmd_debug = format!("{:?}", cmd);
     let mut cmd = cmd.spawn().expect("running rustfmt");
-    // poor man's async: return a box that'll wait for rustfmt's completion
-    Box::new(move || {
+    // poor man's async: return a closure that'll wait for rustfmt's completion
+    move || {
         let status = cmd.wait().unwrap();
         if !status.success() {
             eprintln!(
@@ -34,7 +34,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> Box<im
             );
             std::process::exit(1);
         }
-    })
+    }
 }
 
 #[derive(serde::Deserialize)]
@@ -122,8 +122,8 @@ pub fn format(build: &Build, check: bool) {
         WalkBuilder::new(src.clone()).types(matcher).overrides(ignore_fmt).build_parallel();
 
     // there is a lot of blocking involved in spawning a child process and reading files to format.
-    // spawn more processes than available cores to keep the CPU busy
-    let max_processes = num_cpus::get() * 2;
+    // spawn more processes than available concurrency to keep the CPU busy
+    let max_processes = build.jobs() as usize * 2;
 
     // spawn child processes on a separate thread so we can batch entries we have received from ignore
     let thread = std::thread::spawn(move || {
@@ -135,7 +135,7 @@ pub fn format(build: &Build, check: bool) {
             let child = rustfmt(&src, &rustfmt_path, paths.as_slice(), check);
             children.push_back(child);
 
-            if children.len() > max_processes {
+            if children.len() >= max_processes {
                 // await oldest child
                 children.pop_front().unwrap()();
             }