diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-05-29 15:36:12 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-05-29 18:00:35 +1000 |
| commit | 4dec0a0e9938c0762b6bfcce8b611d5096e32880 (patch) | |
| tree | ee6cab71c0854691c920c4075024109c58d91122 | |
| parent | a22cfccca2a80d15f6b015697e0ada9379d16f73 (diff) | |
| download | rust-4dec0a0e9938c0762b6bfcce8b611d5096e32880.tar.gz rust-4dec0a0e9938c0762b6bfcce8b611d5096e32880.zip | |
Clarify the closure in `rustfmt`.
- Avoid calling `try_wait` followed immediately by `wait`. - Make the match exhaustive. - Improve the comment.
| -rw-r--r-- | src/bootstrap/src/core/build_steps/format.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs index 58342f2d902..601e4e55e09 100644 --- a/src/bootstrap/src/core/build_steps/format.rs +++ b/src/bootstrap/src/core/build_steps/format.rs @@ -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 wait 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 \ |
