@@ -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