From 0307f604ea5ca91de1f65d1db075d5cc5abb00ad Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 15 Nov 2024 18:55:45 -0800 Subject: [PATCH] Resolve question_mark clippy lint in build script 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 --- serde/build.rs | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/serde/build.rs b/serde/build.rs index d7ab56562..24aa0e6d2 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -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 @@ -108,30 +108,12 @@ fn main() { } fn rustc_minor_version() -> Option { - 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() }