refactor: reuse error_missing_print_output on similar errors

This commit is contained in:
Weihang Lo 2023-01-27 02:20:40 +00:00
parent 036ed3a2dd
commit 1cef6d7675
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -219,13 +219,8 @@ impl TargetInfo {
map.insert(crate_type.clone(), out); map.insert(crate_type.clone(), out);
} }
let line = match lines.next() { let Some(line) = lines.next() else {
Some(line) => line, return error_missing_print_output("sysroot", &process, &output, &error);
None => anyhow::bail!(
"output of --print=sysroot missing when learning about \
target-specific information from rustc\n{}",
output_err_info(&process, &output, &error)
),
}; };
let sysroot = PathBuf::from(line); let sysroot = PathBuf::from(line);
let sysroot_host_libdir = if cfg!(windows) { let sysroot_host_libdir = if cfg!(windows) {
@ -601,12 +596,8 @@ fn parse_crate_type(
}; };
let mut parts = line.trim().split("___"); let mut parts = line.trim().split("___");
let prefix = parts.next().unwrap(); let prefix = parts.next().unwrap();
let suffix = match parts.next() { let Some(suffix) = parts.next() else {
Some(part) => part, return error_missing_print_output("file-names", cmd, output, error);
None => anyhow::bail!(
"output of --print=file-names has changed in the compiler, cannot parse\n{}",
output_err_info(cmd, output, error)
),
}; };
Ok(Some((prefix.to_string(), suffix.to_string()))) Ok(Some((prefix.to_string(), suffix.to_string())))