Skip to content

Commit e98740a

Browse files
committed
Clarify x fmt messages.
- Precede them all with `fmt` so it's clear where they are coming from. - Use `error:` and `warning:` when appropriate. - Print warnings to stderr instead of stdout
1 parent 5cf198d commit e98740a

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
3535
let status = cmd.wait().unwrap();
3636
if !status.success() {
3737
eprintln!(
38-
"Running `{}` failed.\nIf you're running `tidy`, \
39-
try again with `--bless`. Or, if you just want to format \
40-
code, run `./x.py fmt` instead.",
38+
"fmt error: Running `{}` failed.\nIf you're running `tidy`, \
39+
try again with `--bless`. Or, if you just want to format \
40+
code, run `./x.py fmt` instead.",
4141
cmd_debug,
4242
);
4343
crate::exit!(1);
@@ -99,7 +99,7 @@ struct RustfmtConfig {
9999

100100
pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
101101
if !paths.is_empty() {
102-
eprintln!("path arguments are not accepted");
102+
eprintln!("fmt error: path arguments are not accepted");
103103
crate::exit!(1);
104104
};
105105
if build.config.dry_run() {
@@ -118,8 +118,8 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
118118
let matcher = builder.build().unwrap();
119119
let rustfmt_config = build.src.join("rustfmt.toml");
120120
if !rustfmt_config.exists() {
121-
eprintln!("Not running formatting checks; rustfmt.toml does not exist.");
122-
eprintln!("This may happen in distributed tarballs.");
121+
eprintln!("fmt error: Not running formatting checks; rustfmt.toml does not exist.");
122+
eprintln!("fmt error: This may happen in distributed tarballs.");
123123
return;
124124
}
125125
let rustfmt_config = t!(std::fs::read_to_string(&rustfmt_config));
@@ -133,7 +133,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
133133
// any files that aren't explicitly mentioned. No bueno! Maybe there's a way to combine
134134
// explicit whitelisted entries and traversal of unmentioned files, but for now just
135135
// forbid such entries.
136-
eprintln!("`!`-prefixed entries are not supported in rustfmt.toml, sorry");
136+
eprintln!("fmt error: `!`-prefixed entries are not supported in rustfmt.toml, sorry");
137137
crate::exit!(1);
138138
} else {
139139
fmt_override.add(&format!("!{ignore}")).expect(&ignore);
@@ -177,7 +177,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
177177
);
178178
let mut untracked_count = 0;
179179
for untracked_path in untracked_paths {
180-
println!("skip untracked path {untracked_path} during rustfmt invocations");
180+
println!("fmt: skip untracked path {untracked_path} during rustfmt invocations");
181181
// The leading `/` makes it an exact match against the
182182
// repository root, rather than a glob. Without that, if you
183183
// have `foo.rs` in the repository root it will also match
@@ -191,7 +191,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
191191
Ok(Some(files)) => {
192192
if files.len() <= 10 {
193193
for file in &files {
194-
println!("formatting modified file {file}");
194+
println!("fmt: formatting modified file {file}");
195195
}
196196
} else {
197197
let pluralized = |count| if count > 1 { "files" } else { "file" };
@@ -205,7 +205,7 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
205205
)
206206
};
207207
println!(
208-
"formatting {} modified {}{}",
208+
"fmt: formatting {} modified {}{}",
209209
files.len(),
210210
pluralized(files.len()),
211211
untracked_msg
@@ -217,24 +217,23 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
217217
}
218218
Ok(None) => {}
219219
Err(err) => {
220-
println!(
221-
"WARN: Something went wrong when running git commands:\n{err}\n\
222-
Falling back to formatting all files."
223-
);
220+
eprintln!("fmt warning: Something went wrong running git commands:");
221+
eprintln!("fmt warning: {err}");
222+
eprintln!("fmt warning: Falling back to formatting all files.");
224223
}
225224
}
226225
}
227226
} else {
228-
println!("Not in git tree. Skipping git-aware format checks");
227+
eprintln!("fmt: warning: Not in git tree. Skipping git-aware format checks");
229228
}
230229
} else {
231-
println!("Could not find usable git. Skipping git-aware format checks");
230+
eprintln!("fmt: warning: Could not find usable git. Skipping git-aware format checks");
232231
}
233232

234233
let fmt_override = fmt_override.build().unwrap();
235234

236235
let rustfmt_path = build.initial_rustfmt().unwrap_or_else(|| {
237-
eprintln!("./x.py fmt is not supported on this channel");
236+
eprintln!("fmt error: `x fmt` is not supported on this channel");
238237
crate::exit!(1);
239238
});
240239
assert!(rustfmt_path.exists(), "{}", rustfmt_path.display());

0 commit comments

Comments
 (0)