]> git.lizzy.rs Git - rust.git/commitdiff
Refactor fn_trait_kind
authorleonardo.yvens <leoyvens@gmail.com>
Wed, 13 Sep 2017 15:19:37 +0000 (12:19 -0300)
committerleonardo.yvens <leoyvens@gmail.com>
Wed, 13 Sep 2017 15:19:37 +0000 (12:19 -0300)
Short and sweet

src/librustc/middle/lang_items.rs

index 9a70d7b9e3f8901175b678f3f6beb8a0db65d18a..086b598497d57a7b127ae5bfd79f554c623114d5 100644 (file)
@@ -78,19 +78,12 @@ pub fn require(&self, it: LangItem) -> Result<DefId, String> {
     }
 
     pub fn fn_trait_kind(&self, id: DefId) -> Option<ty::ClosureKind> {
-        let def_id_kinds = [
-            (self.fn_trait(), ty::ClosureKind::Fn),
-            (self.fn_mut_trait(), ty::ClosureKind::FnMut),
-            (self.fn_once_trait(), ty::ClosureKind::FnOnce),
-            ];
-
-        for &(opt_def_id, kind) in &def_id_kinds {
-            if Some(id) == opt_def_id {
-                return Some(kind);
-            }
+        match Some(id) {
+            x if x == self.fn_trait() => Some(ty::ClosureKind::Fn),
+            x if x == self.fn_mut_trait() => Some(ty::ClosureKind::FnMut),
+            x if x == self.fn_once_trait() =>  Some(ty::ClosureKind::FnOnce),
+            _ => None
         }
-
-        None
     }
 
     $(