Skip to content

Commit 0307f60

Browse files
committed
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
1 parent 8939af4 commit 0307f60

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

serde/build.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22
use std::process::Command;
3-
use std::str::{self, FromStr};
3+
use std::str;
44

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

110110
fn rustc_minor_version() -> Option<u32> {
111-
let rustc = match env::var_os("RUSTC") {
112-
Some(rustc) => rustc,
113-
None => return None,
114-
};
115-
116-
let output = match Command::new(rustc).arg("--version").output() {
117-
Ok(output) => output,
118-
Err(_) => return None,
119-
};
120-
121-
let version = match str::from_utf8(&output.stdout) {
122-
Ok(version) => version,
123-
Err(_) => return None,
124-
};
125-
111+
let rustc = env::var_os("RUSTC")?;
112+
let output = Command::new(rustc).arg("--version").output().ok()?;
113+
let version = str::from_utf8(&output.stdout).ok()?;
126114
let mut pieces = version.split('.');
127115
if pieces.next() != Some("rustc 1") {
128116
return None;
129117
}
130-
131-
let next = match pieces.next() {
132-
Some(next) => next,
133-
None => return None,
134-
};
135-
136-
u32::from_str(next).ok()
118+
pieces.next()?.parse().ok()
137119
}

0 commit comments

Comments
 (0)