Skip to content

Commit 426ad68

Browse files
committed
Simplify build.rs by using the question mark operator
1 parent b514302 commit 426ad68

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

build.rs

+6-20
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,14 @@ fn rustc_minor_nightly() -> (u32, bool) {
231231
}
232232

233233
fn which_freebsd() -> Option<i32> {
234-
let output = std::process::Command::new("freebsd-version").output().ok();
235-
if output.is_none() {
236-
return None;
237-
}
238-
let output = output.unwrap();
234+
let output = std::process::Command::new("freebsd-version")
235+
.output()
236+
.ok()?;
239237
if !output.status.success() {
240238
return None;
241239
}
242240

243-
let stdout = String::from_utf8(output.stdout).ok();
244-
if stdout.is_none() {
245-
return None;
246-
}
247-
let stdout = stdout.unwrap();
241+
let stdout = String::from_utf8(output.stdout).ok()?;
248242

249243
match &stdout {
250244
s if s.starts_with("10") => Some(10),
@@ -260,20 +254,12 @@ fn emcc_version_code() -> Option<u64> {
260254
let output = std::process::Command::new("emcc")
261255
.arg("-dumpversion")
262256
.output()
263-
.ok();
264-
if output.is_none() {
265-
return None;
266-
}
267-
let output = output.unwrap();
257+
.ok()?;
268258
if !output.status.success() {
269259
return None;
270260
}
271261

272-
let stdout = String::from_utf8(output.stdout).ok();
273-
if stdout.is_none() {
274-
return None;
275-
}
276-
let version = stdout.unwrap();
262+
let version = String::from_utf8(output.stdout).ok()?;
277263

278264
// Some Emscripten versions come with `-git` attached, so split the
279265
// version string also on the `-` char.

0 commit comments

Comments
 (0)