]> git.lizzy.rs Git - rust.git/commitdiff
Clean up the logic in `is_min_const_fn`
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 30 Nov 2018 17:07:51 +0000 (18:07 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 4 Dec 2018 09:17:37 +0000 (10:17 +0100)
src/librustc/ty/constness.rs

index f067a125c5dc9b9991a065b0fa7a75da56bcc636..d86170b24f239ec886c302c4be7f9d0a45b1866b 100644 (file)
@@ -40,19 +40,24 @@ pub fn is_unstable_const_fn(self, def_id: DefId) -> Option<Symbol> {
 
     /// Returns true if this function must conform to `min_const_fn`
     pub fn is_min_const_fn(self, def_id: DefId) -> bool {
-        if self.features().staged_api {
-            // some intrinsics are waved through if called inside the
-            // standard library. Users never need to call them directly
-            if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
-                assert!(!self.is_const_fn(def_id));
-                match &self.item_name(def_id).as_str()[..] {
-                    | "size_of"
-                    | "min_align_of"
-                    | "needs_drop"
-                    => return true,
-                    _ => {},
-                }
+        // some intrinsics are waved through if called inside the
+        // standard library. Users never need to call them directly
+        if let abi::Abi::RustIntrinsic = self.fn_sig(def_id).abi() {
+            match &self.item_name(def_id).as_str()[..] {
+                | "size_of"
+                | "min_align_of"
+                | "needs_drop"
+                => return true,
+                _ => {},
             }
+        }
+
+        // Bail out if the signature doesn't contain `const`
+        if !self.is_const_fn_raw(def_id) {
+            return false;
+        }
+
+        if self.features().staged_api {
             // in order for a libstd function to be considered min_const_fn
             // it needs to be stable and have no `rustc_const_unstable` attribute
             self.is_const_fn_raw(def_id) && match self.lookup_stability(def_id) {
@@ -66,7 +71,7 @@ pub fn is_min_const_fn(self, def_id: DefId) -> bool {
             }
         } else {
             // users enabling the `const_fn` feature gate can do what they want
-            self.is_const_fn_raw(def_id) && !self.features().const_fn
+            !self.features().const_fn
         }
     }
 }