@@ -363,7 +363,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
363363 }
364364
365365 fn revalidate_conditional_constness (
366- & self ,
366+ & mut self ,
367367 callee : DefId ,
368368 callee_args : ty:: GenericArgsRef < ' tcx > ,
369369 call_source : CallSource ,
@@ -374,11 +374,24 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
374374 return ;
375375 }
376376
377+ let const_conditions = tcx. const_conditions ( callee) . instantiate ( tcx, callee_args) ;
378+ // If there are any const conditions on this fn and `const_trait_impl`
379+ // is not enabled, simply bail. We shouldn't be able to call conditionally
380+ // const functions on stable.
381+ if !const_conditions. is_empty ( ) && !tcx. features ( ) . const_trait_impl ( ) {
382+ self . check_op ( ops:: FnCallNonConst {
383+ callee,
384+ args : callee_args,
385+ span : call_span,
386+ call_source,
387+ feature : Some ( sym:: const_trait_impl) ,
388+ } ) ;
389+ return ;
390+ }
391+
377392 let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: from_param_env ( self . param_env ) ) ;
378393 let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
379394
380- let const_conditions = tcx. const_conditions ( callee) . instantiate ( tcx, callee_args) ;
381-
382395 let body_id = self . body . source . def_id ( ) . expect_local ( ) ;
383396 let host_polarity = match self . const_kind ( ) {
384397 hir:: ConstContext :: ConstFn => ty:: BoundConstness :: Maybe ,
@@ -621,7 +634,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
621634 } ;
622635
623636 let ConstCx { tcx, body, param_env, .. } = * self . ccx ;
624- let caller = self . def_id ( ) ;
625637
626638 let fn_ty = func. ty ( body, tcx) ;
627639
@@ -639,12 +651,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
639651 }
640652 } ;
641653
642- self . revalidate_conditional_constness (
643- callee,
644- fn_args,
645- call_source,
646- terminator. source_info . span ,
647- ) ;
654+ self . revalidate_conditional_constness ( callee, fn_args, call_source, * fn_span) ;
648655
649656 let mut is_trait = false ;
650657 // Attempting to call a trait method?
@@ -684,7 +691,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
684691 None
685692 } ;
686693 self . check_op ( ops:: FnCallNonConst {
687- caller,
688694 callee,
689695 args : fn_args,
690696 span : * fn_span,
@@ -774,7 +780,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
774780 // Trait functions are not `const fn` so we have to skip them here.
775781 if !tcx. is_const_fn ( callee) && !is_trait {
776782 self . check_op ( ops:: FnCallNonConst {
777- caller,
778783 callee,
779784 args : fn_args,
780785 span : * fn_span,
0 commit comments