@@ -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,6 +848,22 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
846
848
{
847
849
nonconst_call_permission = true ;
848
850
}
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
+ && let FnDef ( def_id, ..) = self_ty. kind ( )
863
+ && tcx. is_const_fn_raw ( * def_id)
864
+ {
865
+ return ;
866
+ }
849
867
850
868
if !nonconst_call_permission {
851
869
let obligation = Obligation :: new (
@@ -865,7 +883,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
865
883
& e,
866
884
) ;
867
885
}
868
-
869
886
self . check_op ( ops:: FnCallNonConst {
870
887
caller,
871
888
callee,
0 commit comments