Skip to content

Commit 224bc05

Browse files
committed
Fix allow_internal_unstable with rustc_const_unstable
1 parent 50fc24d commit 224bc05

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/librustc_mir/transform/check_consts/validation.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,12 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
548548
if is_lang_panic_fn(self.tcx, def_id) {
549549
self.check_op(ops::Panic);
550550
} else if let Some(feature) = is_unstable_const_fn(self.tcx, def_id) {
551-
// Exempt unstable const fns inside of macros with
551+
// Exempt unstable const fns inside of macros or functions with
552552
// `#[allow_internal_unstable]`.
553-
if !self.span.allows_unstable(feature) {
553+
use crate::transform::qualify_min_const_fn::feature_allowed;
554+
if !self.span.allows_unstable(feature)
555+
&& !feature_allowed(self.tcx, self.def_id, feature)
556+
{
554557
self.check_op(ops::FnCallUnstable(def_id, feature));
555558
}
556559
} else {

src/librustc_mir/transform/qualify_min_const_fn.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn check_place(
315315
}
316316

317317
/// Returns `true` if the given feature gate is allowed within the function with the given `DefId`.
318-
fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
318+
pub fn feature_allowed(tcx: TyCtxt<'tcx>, def_id: DefId, feature_gate: Symbol) -> bool {
319319
// All features require that the corresponding gate be enabled,
320320
// even if the function has `#[allow_internal_unstable(the_gate)]`.
321321
if !tcx.features().enabled(feature_gate) {
@@ -377,8 +377,16 @@ fn check_terminator(
377377
fn_span: _,
378378
} => {
379379
let fn_ty = func.ty(body, tcx);
380-
if let ty::FnDef(def_id, _) = fn_ty.kind {
381-
if !crate::const_eval::is_min_const_fn(tcx, def_id) {
380+
if let ty::FnDef(fn_def_id, _) = fn_ty.kind {
381+
// Allow unstable const if we opt in by using #[allow_internal_unstable]
382+
// on function or macro declaration.
383+
if !crate::const_eval::is_min_const_fn(tcx, fn_def_id)
384+
&& !crate::const_eval::is_unstable_const_fn(tcx, fn_def_id)
385+
.map(|feature| {
386+
span.allows_unstable(feature) || feature_allowed(tcx, def_id, feature)
387+
})
388+
.unwrap_or(false)
389+
{
382390
return Err((
383391
span,
384392
format!(
@@ -390,10 +398,10 @@ fn check_terminator(
390398
));
391399
}
392400

393-
check_operand(tcx, func, span, def_id, body)?;
401+
check_operand(tcx, func, span, fn_def_id, body)?;
394402

395403
for arg in args {
396-
check_operand(tcx, arg, span, def_id, body)?;
404+
check_operand(tcx, arg, span, fn_def_id, body)?;
397405
}
398406
Ok(())
399407
} else {

0 commit comments

Comments
 (0)