From 4f3ab4986ec96d9c93f34dc53d0a4a1279288451 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Mon, 23 Jul 2018 22:00:51 -0700 Subject: [PATCH] libstd: Prefer `Option::map`/etc over `match` where applicable --- src/libstd/net/parser.rs | 5 +---- src/libstd/path.rs | 5 +---- src/libstd/sys_common/backtrace.rs | 9 ++++----- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/libstd/net/parser.rs b/src/libstd/net/parser.rs index ae5037cc44e..008c5da171f 100644 --- a/src/libstd/net/parser.rs +++ b/src/libstd/net/parser.rs @@ -53,10 +53,7 @@ fn read_till_eof(&mut self, cb: F) -> Option where F: FnOnce(&mut Parser) -> Option, { self.read_atomically(move |p| { - match cb(p) { - Some(x) => if p.is_eof() {Some(x)} else {None}, - None => None, - } + cb(p).filter(|_| p.is_eof()) }) } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 0c60129494d..688a7e99f10 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1065,10 +1065,7 @@ impl<'a> Iterator for Ancestors<'a> { fn next(&mut self) -> Option { let next = self.next; - self.next = match next { - Some(path) => path.parent(), - None => None, - }; + self.next = next.and_then(Path::parent); next } } diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index 61d7ed463dd..2db47bd5947 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -156,16 +156,15 @@ pub fn log_enabled() -> Option { _ => return Some(PrintFormat::Full), } - let val = match env::var_os("RUST_BACKTRACE") { - Some(x) => if &x == "0" { + let val = env::var_os("RUST_BACKTRACE").and_then(|x| + if &x == "0" { None } else if &x == "full" { Some(PrintFormat::Full) } else { Some(PrintFormat::Short) - }, - None => None, - }; + } + ); ENABLED.store(match val { Some(v) => v as isize, None => 1, -- GitLab