@@ -315,7 +315,7 @@ fn check_place(
315
315
}
316
316
317
317
/// 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 {
319
319
// All features require that the corresponding gate be enabled,
320
320
// even if the function has `#[allow_internal_unstable(the_gate)]`.
321
321
if !tcx. features ( ) . enabled ( feature_gate) {
@@ -377,8 +377,16 @@ fn check_terminator(
377
377
fn_span : _,
378
378
} => {
379
379
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
+ {
382
390
return Err ( (
383
391
span,
384
392
format ! (
@@ -390,10 +398,10 @@ fn check_terminator(
390
398
) ) ;
391
399
}
392
400
393
- check_operand ( tcx, func, span, def_id , body) ?;
401
+ check_operand ( tcx, func, span, fn_def_id , body) ?;
394
402
395
403
for arg in args {
396
- check_operand ( tcx, arg, span, def_id , body) ?;
404
+ check_operand ( tcx, arg, span, fn_def_id , body) ?;
397
405
}
398
406
Ok ( ( ) )
399
407
} else {
0 commit comments