Skip to content

Commit

Permalink
Resolve question_mark clippy lint in build script
Browse files Browse the repository at this point in the history
    warning: this `match` expression can be replaced with `?`
       --> serde/build.rs:111:17
        |
    111 |       let rustc = match env::var_os("RUSTC") {
        |  _________________^
    112 | |         Some(rustc) => rustc,
    113 | |         None => return None,
    114 | |     };
        | |_____^ help: try instead: `env::var_os("RUSTC")?`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
        = note: `-W clippy::question-mark` implied by `-W clippy::all`
        = help: to override `-W clippy::all` add `#[allow(clippy::question_mark)]`

    warning: this `match` expression can be replaced with `?`
       --> serde/build.rs:131:16
        |
    131 |       let next = match pieces.next() {
        |  ________________^
    132 | |         Some(next) => next,
    133 | |         None => return None,
    134 | |     };
        | |_____^ help: try instead: `pieces.next()?`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
  • Loading branch information
dtolnay committed Nov 16, 2024
1 parent 8939af4 commit 0307f60
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions serde/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;
use std::process::Command;
use std::str::{self, FromStr};
use std::str;

// The rustc-cfg strings below are *not* public API. Please let us know by
// opening a GitHub issue if your build environment requires some way to enable
Expand Down Expand Up @@ -108,30 +108,12 @@ fn main() {
}

fn rustc_minor_version() -> Option<u32> {
let rustc = match env::var_os("RUSTC") {
Some(rustc) => rustc,
None => return None,
};

let output = match Command::new(rustc).arg("--version").output() {
Ok(output) => output,
Err(_) => return None,
};

let version = match str::from_utf8(&output.stdout) {
Ok(version) => version,
Err(_) => return None,
};

let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}

let next = match pieces.next() {
Some(next) => next,
None => return None,
};

u32::from_str(next).ok()
pieces.next()?.parse().ok()
}

0 comments on commit 0307f60

Please sign in to comment.