@@ -363,7 +363,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
363
363
}
364
364
365
365
fn revalidate_conditional_constness (
366
- & self ,
366
+ & mut self ,
367
367
callee : DefId ,
368
368
callee_args : ty:: GenericArgsRef < ' tcx > ,
369
369
call_source : CallSource ,
@@ -374,11 +374,24 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
374
374
return ;
375
375
}
376
376
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
+
377
392
let infcx = tcx. infer_ctxt ( ) . build ( TypingMode :: from_param_env ( self . param_env ) ) ;
378
393
let ocx = ObligationCtxt :: new_with_diagnostics ( & infcx) ;
379
394
380
- let const_conditions = tcx. const_conditions ( callee) . instantiate ( tcx, callee_args) ;
381
-
382
395
let body_id = self . body . source . def_id ( ) . expect_local ( ) ;
383
396
let host_polarity = match self . const_kind ( ) {
384
397
hir:: ConstContext :: ConstFn => ty:: BoundConstness :: Maybe ,
@@ -621,7 +634,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
621
634
} ;
622
635
623
636
let ConstCx { tcx, body, param_env, .. } = * self . ccx ;
624
- let caller = self . def_id ( ) ;
625
637
626
638
let fn_ty = func. ty ( body, tcx) ;
627
639
@@ -639,12 +651,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
639
651
}
640
652
} ;
641
653
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) ;
648
655
649
656
let mut is_trait = false ;
650
657
// Attempting to call a trait method?
@@ -684,7 +691,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
684
691
None
685
692
} ;
686
693
self . check_op ( ops:: FnCallNonConst {
687
- caller,
688
694
callee,
689
695
args : fn_args,
690
696
span : * fn_span,
@@ -774,7 +780,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
774
780
// Trait functions are not `const fn` so we have to skip them here.
775
781
if !tcx. is_const_fn ( callee) && !is_trait {
776
782
self . check_op ( ops:: FnCallNonConst {
777
- caller,
778
783
callee,
779
784
args : fn_args,
780
785
span : * fn_span,
0 commit comments