Skip to content

Commit 8f1df30

Browse files
Only require allow_internal_unstable for stable const fn
1 parent ac6eb0d commit 8f1df30

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc_mir/transform/qualify_min_const_fn.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,21 @@ fn check_place(
281281
Ok(())
282282
}
283283

284-
/// Returns whether `allow_internal_unstable(..., <feature_gate>, ...)` is present.
284+
/// Returns `true` if the given feature gate is allowed within the function with the given `DefId`.
285285
fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
286+
// All features require that the corresponding gate be enabled.
287+
if !tcx.features().enabled(feature_gate) {
288+
return false;
289+
}
290+
291+
// If this crate is not using stability attributes, or this function is not claiming to be a
292+
// stable `const fn`, that is all that is required.
293+
if !tcx.features().staged_api || tcx.has_attr(def_id, sym::rustc_const_unstable) {
294+
return true;
295+
}
296+
297+
// However, we cannot allow stable `const fn`s to use unstable features without an explicit
298+
// opt-in via `allow_internal_unstable`.
286299
attr::allow_internal_unstable(&tcx.get_attrs(def_id), &tcx.sess.diagnostic())
287300
.map_or(false, |mut features| features.any(|name| name == feature_gate))
288301
}

0 commit comments

Comments
 (0)