Skip to content

Commit

Permalink
refactor: reuse error_missing_print_output on similar errors
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jan 27, 2023
1 parent 036ed3a commit 1cef6d7
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,8 @@ impl TargetInfo {
map.insert(crate_type.clone(), out);
}

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

Ok(Some((prefix.to_string(), suffix.to_string())))
Expand Down

0 comments on commit 1cef6d7

Please # to comment.