@@ -9,9 +9,11 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
9
9
use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
10
10
use rustc_middle:: mir:: * ;
11
11
use rustc_middle:: traits:: BuiltinImplSource ;
12
+ use rustc_middle:: ty:: FnDef ;
12
13
use rustc_middle:: ty:: GenericArgs ;
13
14
use rustc_middle:: ty:: { self , adjustment:: PointerCoercion , Instance , InstanceDef , Ty , TyCtxt } ;
14
15
use rustc_middle:: ty:: { TraitRef , TypeVisitableExt } ;
16
+ use rustc_middle:: util:: call_kind;
15
17
use rustc_mir_dataflow:: { self , Analysis } ;
16
18
use rustc_span:: { sym, Span , Symbol } ;
17
19
use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
@@ -846,7 +848,24 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
846
848
{
847
849
nonconst_call_permission = true ;
848
850
}
849
-
851
+ let call_kind = call_kind (
852
+ tcx,
853
+ self . param_env ,
854
+ callee,
855
+ fn_args,
856
+ * fn_span,
857
+ call_source. from_hir_call ( ) ,
858
+ None ,
859
+ ) ;
860
+ if let call_kind:: CallKind :: FnCall { fn_trait_id : _, self_ty } =
861
+ call_kind
862
+ {
863
+ if let FnDef ( def_id, ..) = self_ty. kind ( ) {
864
+ if tcx. is_const_fn_raw ( * def_id) {
865
+ return ;
866
+ }
867
+ }
868
+ }
850
869
if !nonconst_call_permission {
851
870
let obligation = Obligation :: new (
852
871
tcx,
@@ -865,7 +884,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
865
884
& e,
866
885
) ;
867
886
}
868
-
869
887
self . check_op ( ops:: FnCallNonConst {
870
888
caller,
871
889
callee,
0 commit comments