Skip to content

Commit f1b0ca0

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 4702a1c commit f1b0ca0

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
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

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version = "Two"
33
use_small_heuristics = "Max"
44
merge_derives = false
55

6-
# Files to ignore. Each entry uses gitignore syntax.
6+
# Files to ignore. Each entry uses gitignore syntax, but `!` prefixes aren't allowed.
77
ignore = [
88
"/build/",
99
"/*-build/",
@@ -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

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)