From 8f1df30d06072f03407654b1cde11a1a067bdfad Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Fri, 10 Jan 2020 16:12:26 -0800 Subject: [PATCH] Only require `allow_internal_unstable` for stable `const fn` --- .../transform/qualify_min_const_fn.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index fcdabb29cd0..74b21435eae 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -281,8 +281,21 @@ fn check_place( Ok(()) } -/// Returns whether `allow_internal_unstable(..., , ...)` is present. +/// Returns `true` if the given feature gate is allowed within the function with the given `DefId`. fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool { + // All features require that the corresponding gate be enabled. + if !tcx.features().enabled(feature_gate) { + return false; + } + + // If this crate is not using stability attributes, or this function is not claiming to be a + // stable `const fn`, that is all that is required. + if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) { + return true; + } + + // However, we cannot allow stable `const fn`s to use unstable features without an explicit + // opt-in via `allow_internal_unstable`. attr::allow_internal_unstable(&tcx.get_attrs(def_id), &tcx.sess.diagnostic()) .map_or(false, |mut features| features.any(|name| name == feature_gate)) }