Skip to content

Commit

Permalink
Update rustc_version_cmd
Browse files Browse the repository at this point in the history
Change `if let` to a `match` because it is about the same complexity but
also works with our MSRV for 0.2. This should allow backporting [1]
easier, as well as future backports that touch this code.

Additionally, add some new documentation comments.

[1]: rust-lang#3893
  • Loading branch information
tgross35 committed Sep 6, 2024
1 parent 37f0e1e commit cdf12d2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,23 @@ fn main() {
}
}

/// Run `rustc --version` and capture the output, adjusting arguments as needed if `clippy-driver`
/// is used instead.
fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty());
let rustc = env::var_os("RUSTC").expect("Failed to get rustc version: missing RUSTC env");

let mut cmd = if let Some(wrapper) = rustc_wrapper {
let mut cmd = Command::new(wrapper);
cmd.arg(rustc);
if is_clippy_driver {
cmd.arg("--rustc");
}
let mut cmd = match rustc_wrapper {
Some(wrapper) => {
let mut cmd = Command::new(wrapper);
cmd.arg(rustc);
if is_clippy_driver {
cmd.arg("--rustc");
}

cmd
} else {
Command::new(rustc)
cmd
}
None => Command::new(rustc),
};

cmd.arg("--version");
Expand All @@ -141,6 +144,8 @@ fn rustc_version_cmd(is_clippy_driver: bool) -> Output {
output
}

/// Return the minor version of `rustc`, as well as a bool indicating whether or not the version
/// is a nightly.
fn rustc_minor_nightly() -> (u32, bool) {
macro_rules! otry {
($e:expr) => {
Expand Down

0 comments on commit cdf12d2

Please sign in to comment.