]> git.lizzy.rs Git - rust.git/commitdiff
enable checking for const fn without needing to go through `entry`
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 9 Dec 2016 15:31:53 +0000 (16:31 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Fri, 9 Dec 2016 15:31:53 +0000 (16:31 +0100)
src/librustc_metadata/decoder.rs

index 2a6063cc4bda95c614daae68b524873463638603..e07868877283f97af8b635b6f78b6e927a4a94fe 100644 (file)
@@ -504,6 +504,14 @@ fn to_def(&self, did: DefId) -> Option<Def> {
             EntryKind::Closure(_) => return None,
         })
     }
+    fn is_const_fn(&self, meta: &CrateMetadata) -> bool {
+        let constness = match *self {
+            EntryKind::Method(data) => data.decode(meta).fn_data.constness,
+            EntryKind::Fn(data) => data.decode(meta).constness,
+            _ => hir::Constness::NotConst,
+        };
+        constness == hir::Constness::Const
+    }
 }
 
 impl<'a, 'tcx> CrateMetadata {
@@ -1051,12 +1059,7 @@ pub fn get_macro(&self, id: DefIndex) -> (ast::Name, MacroDef) {
     }
 
     pub fn is_const_fn(&self, id: DefIndex) -> bool {
-        let constness = match self.entry(id).kind {
-            EntryKind::Method(data) => data.decode(self).fn_data.constness,
-            EntryKind::Fn(data) => data.decode(self).constness,
-            _ => hir::Constness::NotConst,
-        };
-        constness == hir::Constness::Const
+        self.entry(id).kind.is_const_fn(self)
     }
 
     pub fn is_foreign_item(&self, id: DefIndex) -> bool {