Skip to content

Commit 8eb7c58

Browse files
Remove most files from format ignore list
Also moves formatting to use edition 2018, and to be done in parallel. This brings near-linear speed ups (at least with a small amount of cores).
1 parent 9b98af8 commit 8eb7c58

File tree

2 files changed

+73
-85
lines changed

2 files changed

+73
-85
lines changed

rustfmt.toml

+50-65
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,59 @@
1-
# Currently, most of the code in the compiler uses historical style.
2-
#
3-
# For new code, consider running rustfmt with this config (it should
4-
# be picked up automatically).
1+
# Run rustfmt with this config (it should be picked up automatically).
52
version = "Two"
63
use_small_heuristics = "Max"
4+
merge_derives = false
75

86
# by default we ignore everything in the repository
97
# tidy only checks files which are not ignored, each entry follows gitignore style
108
ignore = [
11-
# remove directories below, or opt out their subdirectories, as they are formatted
12-
"src/bootstrap/",
13-
"src/build_helper/",
14-
"src/liballoc/",
15-
"src/libarena/",
16-
"src/libcore/",
17-
"src/libfmt_macros/",
18-
"src/libgraphviz/",
19-
"src/libpanic_abort/",
20-
"src/libpanic_unwind/",
21-
"src/libproc_macro/",
22-
"src/libprofiler_builtins/",
23-
"src/librustc/",
24-
"src/librustc_apfloat/",
25-
"src/librustc_asan/",
26-
"src/librustc_codegen_llvm/",
27-
"src/librustc_codegen_ssa/",
28-
"src/librustc_codegen_utils/",
29-
"src/librustc_data_structures/",
30-
"src/librustc_driver/",
31-
"src/librustc_errors/",
32-
"src/librustc_feature/",
33-
"src/librustc_incremental/",
34-
"src/librustc_index/",
35-
"src/librustc_interface/",
36-
"src/librustc_lexer/",
37-
"src/librustc_lint/",
38-
"src/librustc_llvm/",
39-
"src/librustc_lsan/",
40-
"src/librustc_macros/",
41-
"src/librustc_metadata/",
42-
"src/librustc_mir/",
43-
"src/librustc_msan/",
44-
"src/librustc_parse/",
45-
"src/librustc_passes/",
46-
"src/librustc_plugin/",
47-
"src/librustc_plugin_impl/",
48-
"src/librustc_privacy/",
49-
"src/librustc_resolve/",
50-
"src/librustc_save_analysis/",
51-
"src/librustc_session/",
52-
"src/librustc_target/",
53-
"src/librustc_traits/",
54-
"src/librustc_tsan/",
55-
"src/librustc_typeck/",
56-
"src/librustdoc/",
57-
"src/libserialize/",
58-
"src/libstd/",
59-
"src/libsyntax/",
60-
"src/libsyntax_expand/",
61-
"src/libsyntax_ext/",
62-
"src/libsyntax_pos/",
63-
"src/libterm/",
64-
"src/libtest/",
65-
"src/libunwind/",
66-
"src/rtstartup/",
67-
"src/rustc/",
68-
"src/rustllvm/",
69-
"src/test/",
70-
"src/tools/",
71-
"src/etc",
9+
# tests for now are not formatted, as they are sometimes pretty-printing constrained
10+
# (and generally rustfmt can move around comments in UI-testing incompatible ways)
11+
"src/test",
12+
13+
# tidy issues (line length, etc.)
14+
# to be fixed shortly
15+
"src/libcore/iter/adapters/mod.rs",
16+
"src/libcore/iter/traits/iterator.rs",
17+
"src/librustc/hir/lowering.rs",
18+
"src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs",
19+
"src/librustc/lint/mod.rs",
20+
"src/librustc/middle/resolve_lifetime.rs",
21+
"src/librustc/traits/mod.rs",
22+
"src/librustc/ty/constness.rs",
23+
"src/librustc/ty/context.rs",
24+
"src/librustc/ty/wf.rs",
25+
"src/librustc_codegen_llvm/back/write.rs",
26+
"src/librustc_codegen_llvm/consts.rs",
27+
"src/librustc_codegen_llvm/debuginfo/metadata.rs",
28+
"src/librustc_codegen_ssa/base.rs",
29+
"src/librustc_codegen_ssa/mir/place.rs",
30+
"src/librustc_codegen_utils/symbol_names/v0.rs",
31+
"src/librustc_errors/emitter.rs",
32+
"src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs",
33+
"src/librustc_mir/borrow_check/type_check/mod.rs",
34+
"src/librustc_mir/build/expr/as_rvalue.rs",
35+
"src/librustc_mir/build/matches/mod.rs",
36+
"src/librustc_mir/build/mod.rs",
37+
"src/librustc_mir/const_eval.rs",
38+
"src/librustc_mir/interpret/place.rs",
39+
"src/librustc_mir/monomorphize/collector.rs",
40+
"src/librustc_passes/ast_validation.rs",
41+
"src/librustc_resolve/lib.rs",
42+
"src/librustc_resolve/resolve_imports.rs",
43+
"src/librustc_typeck/astconv.rs",
44+
"src/librustc_typeck/check/_match.rs",
45+
"src/librustc_typeck/check/coercion.rs",
46+
"src/librustc_typeck/check/method/confirm.rs",
47+
"src/librustc_typeck/check/mod.rs",
48+
"src/librustc_typeck/check/wfcheck.rs",
49+
"src/librustdoc/html/markdown/tests.rs",
50+
"src/libstd/sys/sgx/abi/mem.rs",
51+
"src/libstd/sys/unix/os.rs",
52+
"src/libsyntax_expand/parse/lexer/tests.rs",
53+
"src/libsyntax_expand/parse/tests.rs",
54+
"src/libsyntax_ext/test.rs",
55+
"src/tools/build-manifest/src/main.rs",
56+
"src/librustc_feature",
7257

7358
# do not format submodules
7459
"src/doc/book",

src/bootstrap/format.rs

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
//! Runs rustfmt on the repository.
22
33
use crate::Build;
4-
use std::process::Command;
4+
use build_helper::t;
55
use ignore::WalkBuilder;
66
use std::path::Path;
7-
use build_helper::t;
8-
9-
fn rustfmt(build: &Build, path: &Path, check: bool) {
10-
let rustfmt_path = build.config.initial_rustfmt.as_ref().unwrap_or_else(|| {
11-
eprintln!("./x.py fmt is not supported on this channel");
12-
std::process::exit(1);
13-
});
7+
use std::process::Command;
148

15-
let mut cmd = Command::new(&rustfmt_path);
9+
fn rustfmt(src: &Path, rustfmt: &Path, path: &Path, check: bool) {
10+
let mut cmd = Command::new(&rustfmt);
1611
// avoid the submodule config paths from coming into play,
1712
// we only allow a single global config for the workspace for now
18-
cmd.arg("--config-path").arg(&build.src.canonicalize().unwrap());
13+
cmd.arg("--config-path").arg(&src.canonicalize().unwrap());
14+
cmd.arg("--edition").arg("2018");
1915
cmd.arg("--unstable-features");
2016
cmd.arg("--skip-children");
2117
if check {
@@ -51,14 +47,21 @@ pub fn format(build: &Build, check: bool) {
5147
}
5248
let ignore_fmt = ignore_fmt.build().unwrap();
5349

54-
let walker = WalkBuilder::new(&build.src)
55-
.types(matcher)
56-
.overrides(ignore_fmt)
57-
.build();
58-
for entry in walker {
59-
let entry = t!(entry);
60-
if entry.file_type().map_or(false, |t| t.is_file()) {
61-
rustfmt(build, &entry.path(), check);
62-
}
63-
}
50+
let rustfmt_path = build.config.initial_rustfmt.as_ref().unwrap_or_else(|| {
51+
eprintln!("./x.py fmt is not supported on this channel");
52+
std::process::exit(1);
53+
});
54+
let src = build.src.clone();
55+
let walker = WalkBuilder::new(&build.src).types(matcher).overrides(ignore_fmt).build_parallel();
56+
walker.run(|| {
57+
let src = src.clone();
58+
let rustfmt_path = rustfmt_path.clone();
59+
Box::new(move |entry| {
60+
let entry = t!(entry);
61+
if entry.file_type().map_or(false, |t| t.is_file()) {
62+
rustfmt(&src, &rustfmt_path, &entry.path(), check);
63+
}
64+
ignore::WalkState::Continue
65+
})
66+
});
6467
}

0 commit comments

Comments
 (0)