diff --git a/src/librustc/ty/constness.rs b/src/librustc/ty/constness.rs index f067a125c5dc9..d86170b24f239 100644 --- a/src/librustc/ty/constness.rs +++ b/src/librustc/ty/constness.rs @@ -40,19 +40,24 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { /// 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 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { } } 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 } } }