Skip to content

Commit

Permalink
Clarify the closure in rustfmt.
Browse files Browse the repository at this point in the history
- Avoid calling `try_wait` followed immediately by `wait`.
- Make the match exhaustive.
- Improve the comment.
  • Loading branch information
nnethercote committed May 29, 2024
1 parent a22cfcc commit b872585
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
cmd.args(paths);
let cmd_debug = format!("{cmd:?}");
let mut cmd = cmd.spawn().expect("running rustfmt");
// Poor man's async: return a closure that'll wait for rustfmt's completion.
// Poor man's async: return a closure that might for rustfmt's completion (depending on the
// value of the `block` argument).
move |block: bool| -> bool {
if !block {
let status = if !block {
match cmd.try_wait() {
Ok(Some(_)) => {}
_ => return false,
Ok(Some(status)) => Ok(status),
Ok(None) => return false,
Err(err) => Err(err),
}
}
let status = cmd.wait().unwrap();
if !status.success() {
} else {
cmd.wait()
};
if !status.unwrap().success() {
eprintln!(
"fmt error: Running `{}` failed.\nIf you're running `tidy`, \
try again with `--bless`. Or, if you just want to format \
Expand Down

0 comments on commit b872585

Please sign in to comment.