Clarify the closure in rustfmt
.
- Avoid calling `try_wait` followed immediately by `wait`. - Make the match exhaustive. - Improve the comment.
This commit is contained in:
parent
a22cfccca2
commit
4dec0a0e99
@ -25,16 +25,19 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
|
|||||||
cmd.args(paths);
|
cmd.args(paths);
|
||||||
let cmd_debug = format!("{cmd:?}");
|
let cmd_debug = format!("{cmd:?}");
|
||||||
let mut cmd = cmd.spawn().expect("running rustfmt");
|
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 {
|
move |block: bool| -> bool {
|
||||||
if !block {
|
let status = if !block {
|
||||||
match cmd.try_wait() {
|
match cmd.try_wait() {
|
||||||
Ok(Some(_)) => {}
|
Ok(Some(status)) => Ok(status),
|
||||||
_ => return false,
|
Ok(None) => return false,
|
||||||
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
let status = cmd.wait().unwrap();
|
cmd.wait()
|
||||||
if !status.success() {
|
};
|
||||||
|
if !status.unwrap().success() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"fmt error: Running `{}` failed.\nIf you're running `tidy`, \
|
"fmt error: Running `{}` failed.\nIf you're running `tidy`, \
|
||||||
try again with `--bless`. Or, if you just want to format \
|
try again with `--bless`. Or, if you just want to format \
|
||||||
|
Loading…
Reference in New Issue
Block a user