Skip to content

Commit b26b68e

Browse files
committed
Don't format tests/run-make/*/rmake.rs.
It's reasonable to want to, but in the current implementation this causes multiple problems. - All the `rmake.rs` files are formatted every time even when they haven't changed. This is because they get whitelisted unconditionally in the `OverrideBuilder`, before the changed files get added. - The way `OverrideBuilder` works, if any files gets whitelisted then no unmentioned files will get traversed. This is surprising, and means that the `rmake.rs` entries broke the use of explicit paths to `x fmt`, and also broke `GITHUB_ACTIONS=true git check --fmt`. The commit removes the `rmake.rs` entries, fixes the formatting of a couple of files that were misformatted (not previously caught due to the `GITHUB_ACTIONS` breakage), and bans `!`-prefixed entries in `rustfmt.toml` because they cause all these problems.
1 parent 70d1595 commit b26b68e

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

Diff for: compiler/rustc_mir_transform/src/validate.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
689689
if Some(adt_def.did()) == self.tcx.lang_items().dyn_metadata() {
690690
self.fail(
691691
location,
692-
format!("You can't project to field {f:?} of `DynMetadata` because \
693-
layout is weird and thinks it doesn't have fields."),
692+
format!(
693+
"You can't project to field {f:?} of `DynMetadata` because \
694+
layout is weird and thinks it doesn't have fields."
695+
),
694696
);
695697
}
696698

Diff for: 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`

Diff for: rustfmt.toml

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ ignore = [
1212

1313
# tests for now are not formatted, as they are sometimes pretty-printing constrained
1414
# (and generally rustfmt can move around comments in UI-testing incompatible ways)
15-
"/tests/*",
16-
17-
# but we still want to format rmake.rs files in tests/run-make/ so we need to do this
18-
# dance to avoid the parent directory from being excluded
19-
"!/tests/run-make/",
20-
"/tests/run-make/*/*.rs",
21-
"!/tests/run-make/*/rmake.rs",
15+
"/tests/",
2216

2317
# do not format submodules
2418
# FIXME: sync submodule list with tidy/bootstrap/etc

Diff for: src/bootstrap/src/core/build_steps/format.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -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
}

0 commit comments

Comments
 (0)