about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2020-01-10 16:12:26 -0800
committerDylan MacKenzie <ecstaticmorse@gmail.com>2020-01-10 17:18:25 -0800
commit8f1df30d06072f03407654b1cde11a1a067bdfad (patch)
tree2d7e164ab92874f8982fae5e20e3995d53d62d80
parentac6eb0db01a781d4f4940b34bd4c1cbe7e75263a (diff)
downloadrust-8f1df30d06072f03407654b1cde11a1a067bdfad.tar.gz
rust-8f1df30d06072f03407654b1cde11a1a067bdfad.zip
Only require `allow_internal_unstable` for stable `const fn`
-rw-r--r--src/librustc_mir/transform/qualify_min_const_fn.rs15
1 files changed, 14 insertions, 1 deletions
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(..., <feature_gate>, ...)` 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))
 }