Skip to content

Commit 4dec0a0

Browse files
committed
Clarify the closure in rustfmt.
- Avoid calling `try_wait` followed immediately by `wait`. - Make the match exhaustive. - Improve the comment.
1 parent a22cfcc commit 4dec0a0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

+10-7
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
2525
cmd.args(paths);
2626
let cmd_debug = format!("{cmd:?}");
2727
let mut cmd = cmd.spawn().expect("running rustfmt");
28-
// Poor man's async: return a closure that'll wait for rustfmt's completion.
28+
// Poor man's async: return a closure that might wait for rustfmt's completion (depending on
29+
// the value of the `block` argument).
2930
move |block: bool| -> bool {
30-
if !block {
31+
let status = if !block {
3132
match cmd.try_wait() {
32-
Ok(Some(_)) => {}
33-
_ => return false,
33+
Ok(Some(status)) => Ok(status),
34+
Ok(None) => return false,
35+
Err(err) => Err(err),
3436
}
35-
}
36-
let status = cmd.wait().unwrap();
37-
if !status.success() {
37+
} else {
38+
cmd.wait()
39+
};
40+
if !status.unwrap().success() {
3841
eprintln!(
3942
"fmt error: Running `{}` failed.\nIf you're running `tidy`, \
4043
try again with `--bless`. Or, if you just want to format \

0 commit comments

Comments
 (0)