From b75d5f18677fadef03cc55887a18c804af527d9f Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 30 Nov 2018 18:07:51 +0100 Subject: [PATCH] Clean up the logic in `is_min_const_fn` --- src/librustc/ty/constness.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs index f067a125c5d..d86170b24f2 100644 --- a/src/librustc/ty/constness.rs +++ b/src/librustc/ty/constness.rs @@ -40,19 +40,24 @@ pub fn is_unstable_const_fn(self, def_id: DefId) -> Option { /// 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 } } } -- 2.44.0