Skip to content

Commit faabc74

Browse files
authored
Rollup merge of #125637 - nnethercote:rustfmt-fixes, r=GuillaumeGomez
rustfmt fixes The `rmake.rs` entries in `rustfmt.toml` are causing major problems for `x fmt`. This PR removes them and does some minor related cleanups. r? ``@GuillaumeGomez``
2 parents de2bf36 + f1b0ca0 commit faabc74

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

compiler/rustc_mir_transform/src/instsimplify.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,8 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
219219
for (i, field) in variant.fields.iter_enumerated() {
220220
let field_ty = field.ty(self.tcx, args);
221221
if field_ty == *cast_ty {
222-
let place = place.project_deeper(
223-
&[ProjectionElem::Field(i, *cast_ty)],
224-
self.tcx,
225-
);
222+
let place = place
223+
.project_deeper(&[ProjectionElem::Field(i, *cast_ty)], self.tcx);
226224
let operand = if operand.is_move() {
227225
Operand::Move(place)
228226
} else {

compiler/rustc_mir_transform/src/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
691691
location,
692692
format!(
693693
"You can't project to field {f:?} of `DynMetadata` because \
694-
layout is weird and thinks it doesn't have fields."
694+
layout is weird and thinks it doesn't have fields."
695695
),
696696
);
697697
}

library/core/src/ptr/metadata.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,14 @@ impl<Dyn: ?Sized> DynMetadata<Dyn> {
209209
// Consider a reference like `&(i32, dyn Send)`: the vtable will only store the size of the
210210
// `Send` part!
211211
// SAFETY: DynMetadata always contains a valid vtable pointer
212-
return unsafe {
213-
crate::intrinsics::vtable_size(self.vtable_ptr() as *const ())
214-
};
212+
return unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) };
215213
}
216214

217215
/// Returns the alignment of the type associated with this vtable.
218216
#[inline]
219217
pub fn align_of(self) -> usize {
220218
// SAFETY: DynMetadata always contains a valid vtable pointer
221-
return unsafe {
222-
crate::intrinsics::vtable_align(self.vtable_ptr() as *const ())
223-
};
219+
return unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) };
224220
}
225221

226222
/// Returns the size and alignment together as a `Layout`

rustfmt.toml

+6-13
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,18 @@ version = "Two"
33
use_small_heuristics = "Max"
44
merge_derives = false
55

6-
# by default we ignore everything in the repository
7-
# tidy only checks files which are not ignored, each entry follows gitignore style
6+
# Files to ignore. Each entry uses gitignore syntax, but `!` prefixes aren't allowed.
87
ignore = [
98
"/build/",
109
"/*-build/",
1110
"/build-*/",
1211
"/vendor/",
1312

14-
# tests for now are not formatted, as they are sometimes pretty-printing constrained
15-
# (and generally rustfmt can move around comments in UI-testing incompatible ways)
16-
"/tests/*",
13+
# Tests for now are not formatted, as they are sometimes pretty-printing constrained
14+
# (and generally rustfmt can move around comments in UI-testing incompatible ways).
15+
"/tests/",
1716

18-
# but we still want to format rmake.rs files in tests/run-make/ so we need to do this
19-
# dance to avoid the parent directory from being excluded
20-
"!/tests/run-make/",
21-
"/tests/run-make/*/*.rs",
22-
"!/tests/run-make/*/rmake.rs",
23-
24-
# do not format submodules
17+
# Do not format submodules.
2518
# FIXME: sync submodule list with tidy/bootstrap/etc
2619
# tidy/src/walk.rs:filter_dirs
2720
"library/backtrace",
@@ -43,7 +36,7 @@ ignore = [
4336
"src/tools/rustc-perf",
4437
"src/tools/rustfmt",
4538

46-
# these are ignored by a standard cargo fmt run
39+
# These are ignored by a standard cargo fmt run.
4740
"compiler/rustc_codegen_cranelift/scripts",
4841
"compiler/rustc_codegen_cranelift/example/gen_block_iterate.rs", # uses edition 2024
4942
]

src/bootstrap/src/core/build_steps/format.rs

+26-16
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::sync::mpsc::SyncSender;
1212

1313
fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl FnMut(bool) -> bool {
1414
let mut cmd = Command::new(rustfmt);
15-
// avoid the submodule config paths from coming into play,
16-
// we only allow a single global config for the workspace for now
15+
// Avoid the submodule config paths from coming into play. We only allow a single global config
16+
// for the workspace for now.
1717
cmd.arg("--config-path").arg(&src.canonicalize().unwrap());
1818
cmd.arg("--edition").arg("2021");
1919
cmd.arg("--unstable-features");
@@ -24,7 +24,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
2424
cmd.args(paths);
2525
let cmd_debug = format!("{cmd:?}");
2626
let mut cmd = cmd.spawn().expect("running rustfmt");
27-
// poor man's async: return a closure that'll wait for rustfmt's completion
27+
// Poor man's async: return a closure that'll wait for rustfmt's completion.
2828
move |block: bool| -> bool {
2929
if !block {
3030
match cmd.try_wait() {
@@ -72,7 +72,7 @@ fn verify_rustfmt_version(build: &Builder<'_>) -> bool {
7272
!program_out_of_date(&stamp_file, &version)
7373
}
7474

75-
/// Updates the last rustfmt version used
75+
/// Updates the last rustfmt version used.
7676
fn update_rustfmt_version(build: &Builder<'_>) {
7777
let Some((version, stamp_file)) = get_rustfmt_version(build) else {
7878
return;
@@ -115,8 +115,15 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
115115
let rustfmt_config: RustfmtConfig = t!(toml::from_str(&rustfmt_config));
116116
let mut fmt_override = ignore::overrides::OverrideBuilder::new(&build.src);
117117
for ignore in rustfmt_config.ignore {
118-
if let Some(ignore) = ignore.strip_prefix('!') {
119-
fmt_override.add(ignore).expect(ignore);
118+
if ignore.starts_with('!') {
119+
// A `!`-prefixed entry could be added as a whitelisted entry in `fmt_override`, i.e.
120+
// strip the `!` prefix. But as soon as whitelisted entries are added, an
121+
// `OverrideBuilder` will only traverse those whitelisted entries, and won't traverse
122+
// any files that aren't explicitly mentioned. No bueno! Maybe there's a way to combine
123+
// explicit whitelisted entries and traversal of unmentioned files, but for now just
124+
// forbid such entries.
125+
eprintln!("`!`-prefixed entries are not supported in rustfmt.toml, sorry");
126+
crate::exit!(1);
120127
} else {
121128
fmt_override.add(&format!("!{ignore}")).expect(&ignore);
122129
}
@@ -168,9 +175,10 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
168175
untracked_count += 1;
169176
fmt_override.add(&format!("!/{untracked_path}")).expect(untracked_path);
170177
}
171-
// Only check modified files locally to speed up runtime.
172-
// We still check all files in CI to avoid bugs in `get_modified_rs_files` letting regressions slip through;
173-
// we also care about CI time less since this is still very fast compared to building the compiler.
178+
// Only check modified files locally to speed up runtime. We still check all files in
179+
// CI to avoid bugs in `get_modified_rs_files` letting regressions slip through; we
180+
// also care about CI time less since this is still very fast compared to building the
181+
// compiler.
174182
if !CiEnv::is_ci() && paths.is_empty() {
175183
match get_modified_rs_files(build) {
176184
Ok(Some(files)) => {
@@ -275,21 +283,23 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
275283
.overrides(fmt_override)
276284
.build_parallel();
277285

278-
// there is a lot of blocking involved in spawning a child process and reading files to format.
279-
// spawn more processes than available concurrency to keep the CPU busy
286+
// There is a lot of blocking involved in spawning a child process and reading files to format.
287+
// Spawn more processes than available concurrency to keep the CPU busy.
280288
let max_processes = build.jobs() as usize * 2;
281289

282-
// spawn child processes on a separate thread so we can batch entries we have received from ignore
290+
// Spawn child processes on a separate thread so we can batch entries we have received from
291+
// ignore.
283292
let thread = std::thread::spawn(move || {
284293
let mut children = VecDeque::new();
285294
while let Ok(path) = rx.recv() {
286-
// try getting more paths from the channel to amortize the overhead of spawning processes
295+
// Try getting more paths from the channel to amortize the overhead of spawning
296+
// processes.
287297
let paths: Vec<_> = rx.try_iter().take(63).chain(std::iter::once(path)).collect();
288298

289299
let child = rustfmt(&src, &rustfmt_path, paths.as_slice(), check);
290300
children.push_back(child);
291301

292-
// poll completion before waiting
302+
// Poll completion before waiting.
293303
for i in (0..children.len()).rev() {
294304
if children[i](false) {
295305
children.swap_remove_back(i);
@@ -298,12 +308,12 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
298308
}
299309

300310
if children.len() >= max_processes {
301-
// await oldest child
311+
// Await oldest child.
302312
children.pop_front().unwrap()(true);
303313
}
304314
}
305315

306-
// await remaining children
316+
// Await remaining children.
307317
for mut child in children {
308318
child(true);
309319
}

0 commit comments

Comments
 (0)