Skip to content

Commit cc9d7ff

Browse files
committed
Auto merge of #7966 - Alexendoo:batch-rustfmt, r=camsteffen
Run rustfmt on batches of multiple files changelog: none This gives `cargo dev fmt` a nice speed boost, down from 90s (because old) on my laptop and 120s (because windows) on my desktop to ~5s on both 250 at a time was to give windows a good amount of headroom (failed at ~800, rust-lang/rust#40384) Also adds rustfmt to the toolchain file and has the clippy_dev workflow test using the pinned version as a follow up to #7963
2 parents 4f82dd8 + 507030f commit cc9d7ff

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

.github/workflows/clippy_dev.yml

-12
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ jobs:
2525
- name: Checkout
2626
uses: actions/[email protected]
2727

28-
- name: remove toolchain file
29-
run: rm rust-toolchain
30-
31-
- name: rust-toolchain
32-
uses: actions-rs/[email protected]
33-
with:
34-
toolchain: nightly
35-
target: x86_64-unknown-linux-gnu
36-
profile: minimal
37-
components: rustfmt
38-
default: true
39-
4028
# Run
4129
- name: Build
4230
run: cargo build --features deny-warnings

clippy_dev/src/fmt.rs

+24-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::clippy_project_root;
2+
use itertools::Itertools;
23
use shell_escape::escape;
3-
use std::ffi::OsStr;
4+
use std::ffi::{OsStr, OsString};
45
use std::path::Path;
56
use std::process::{self, Command};
67
use std::{fs, io};
@@ -56,15 +57,22 @@ pub fn run(check: bool, verbose: bool) {
5657
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
5758
success &= cargo_fmt(context, &project_root.join("lintcheck"))?;
5859

59-
for entry in WalkDir::new(project_root.join("tests")) {
60-
let entry = entry?;
61-
let path = entry.path();
62-
63-
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
64-
continue;
65-
}
66-
67-
success &= rustfmt(context, path)?;
60+
let chunks = WalkDir::new(project_root.join("tests"))
61+
.into_iter()
62+
.filter_map(|entry| {
63+
let entry = entry.expect("failed to find tests");
64+
let path = entry.path();
65+
66+
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
67+
None
68+
} else {
69+
Some(entry.into_path().into_os_string())
70+
}
71+
})
72+
.chunks(250);
73+
74+
for chunk in &chunks {
75+
success &= rustfmt(context, chunk)?;
6876
}
6977

7078
Ok(success)
@@ -185,14 +193,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
185193
}
186194
}
187195

188-
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
189-
let mut args = vec![path.as_os_str()];
196+
fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Result<bool, CliError> {
197+
let mut args = Vec::new();
190198
if context.check {
191-
args.push("--check".as_ref());
199+
args.push(OsString::from("--check"));
192200
}
201+
args.extend(paths);
202+
193203
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
194-
if !success {
195-
eprintln!("rustfmt failed on {}", path.display());
196-
}
204+
197205
Ok(success)
198206
}

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
channel = "nightly-2021-11-04"
3-
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
3+
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

0 commit comments

Comments
 (0)