about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorShanavas M <shanavas.m2@gmail.com>2017-11-11 17:01:55 +0300
committerShanavas M <shanavas.m2@gmail.com>2017-11-11 17:32:29 +0300
commitabff092f907bff0bdf3f640692494f0b7430efa0 (patch)
tree62c5a7904e151a1156ca44ee3e8ea19fdf19948d /src/libcore
parent69ee5a8a9787336f8635ec12ed0c6199a70505e0 (diff)
downloadrust-abff092f907bff0bdf3f640692494f0b7430efa0.tar.gz
rust-abff092f907bff0bdf3f640692494f0b7430efa0.zip
Refactor Option::filter method
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/option.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 63c846b25ec..12e6e843056 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -634,16 +634,12 @@ impl<T> Option<T> {
     #[inline]
     #[unstable(feature = "option_filter", issue = "45860")]
     pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
-        match self {
-            Some(x) => {
-                if predicate(&x) {
-                    Some(x)
-                } else {
-                    None
-                }
+        if let Some(x) = self {
+            if predicate(&x) {
+                return Some(x)
             }
-            None => None,
         }
+        None
     }
 
     /// Returns the option if it contains a value, otherwise returns `optb`.