about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSebastian Geisler <sebastian@blockstream.io>2018-11-15 22:56:07 -0800
committerSebastian Geisler <sebastian@blockstream.io>2018-11-15 22:56:07 -0800
commitf2106d0746cdbd04ddad44c35b4e13eeced2a546 (patch)
treef1632da493641386c0ce885f12379009e60ae997
parent86ef38b3b7a24959ca11a29c79cf921ed5986bc9 (diff)
downloadrust-f2106d0746cdbd04ddad44c35b4e13eeced2a546.tar.gz
rust-f2106d0746cdbd04ddad44c35b4e13eeced2a546.zip
use ? operator instead of match
-rw-r--r--src/libstd/sys/redox/time.rs13
-rw-r--r--src/libstd/sys/unix/time.rs13
2 files changed, 6 insertions, 20 deletions
diff --git a/src/libstd/sys/redox/time.rs b/src/libstd/sys/redox/time.rs
index 5f8799489aa..514629282ac 100644
--- a/src/libstd/sys/redox/time.rs
+++ b/src/libstd/sys/redox/time.rs
@@ -46,25 +46,18 @@ impl Timespec {
     }
 
     fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> {
-        let mut secs = match other
+        let mut secs = other
             .as_secs()
             .try_into() // <- target type would be `i64`
             .ok()
-            .and_then(|secs| self.t.tv_sec.checked_add(secs))
-        {
-            Some(ts) => ts,
-            None => return None,
-        };
+            .and_then(|secs| self.t.tv_sec.checked_add(secs))?;
 
         // Nano calculations can't overflow because nanos are <1B which fit
         // in a u32.
         let mut nsec = other.subsec_nanos() + self.t.tv_nsec as u32;
         if nsec >= NSEC_PER_SEC as u32 {
             nsec -= NSEC_PER_SEC as u32;
-            secs = match secs.checked_add(1) {
-                Some(ts) => ts,
-                None => return None,
-            }
+            secs = secs.checked_add(1)?;
         }
         Some(Timespec {
             t: syscall::TimeSpec {
diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs
index 50c3c00382e..6c7ee3dd922 100644
--- a/src/libstd/sys/unix/time.rs
+++ b/src/libstd/sys/unix/time.rs
@@ -47,25 +47,18 @@ impl Timespec {
     }
 
     fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> {
-        let mut secs = match other
+        let mut secs = other
             .as_secs()
             .try_into() // <- target type would be `libc::time_t`
             .ok()
-            .and_then(|secs| self.t.tv_sec.checked_add(secs))
-        {
-            Some(ts) => ts,
-            None => return None,
-        };
+            .and_then(|secs| self.t.tv_sec.checked_add(secs))?;
 
         // Nano calculations can't overflow because nanos are <1B which fit
         // in a u32.
         let mut nsec = other.subsec_nanos() + self.t.tv_nsec as u32;
         if nsec >= NSEC_PER_SEC as u32 {
             nsec -= NSEC_PER_SEC as u32;
-            secs = match secs.checked_add(1) {
-                Some(ts) => ts,
-                None => return None,
-            }
+            secs = secs.checked_add(1)?;
         }
         Some(Timespec {
             t: libc::timespec {