Use question mark on Option

This commit is contained in:
David Tolnay 2019-07-19 11:54:35 -07:00
parent f081412819
commit 25ae9526bc
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -88,20 +88,10 @@ struct RustcVersion {
} }
fn rustc_version() -> Option<RustcVersion> { fn rustc_version() -> Option<RustcVersion> {
macro_rules! otry { let rustc = env::var_os("RUSTC")?;
($e:expr) => { let output = Command::new(rustc).arg("--version").output().ok()?;
match $e { let version = str::from_utf8(&output.stdout).ok()?;
Some(e) => e,
None => return None,
}
};
}
let rustc = otry!(env::var_os("RUSTC"));
let output = otry!(Command::new(rustc).arg("--version").output().ok());
let version = otry!(str::from_utf8(&output.stdout).ok());
let nightly = version.contains("nightly"); let nightly = version.contains("nightly");
Some(RustcVersion { nightly }) Some(RustcVersion { nightly })
} }