@@ -9,9 +9,11 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
99use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
1010use rustc_middle:: mir:: * ;
1111use rustc_middle:: traits:: BuiltinImplSource ;
12+ use rustc_middle:: ty:: FnDef ;
1213use rustc_middle:: ty:: GenericArgs ;
1314use rustc_middle:: ty:: { self , adjustment:: PointerCoercion , Instance , InstanceDef , Ty , TyCtxt } ;
1415use rustc_middle:: ty:: { TraitRef , TypeVisitableExt } ;
16+ use rustc_middle:: util:: call_kind;
1517use rustc_mir_dataflow:: { self , Analysis } ;
1618use rustc_span:: { sym, Span , Symbol } ;
1719use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
@@ -846,6 +848,22 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
846848 {
847849 nonconst_call_permission = true ;
848850 }
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+ }
849867
850868 if !nonconst_call_permission {
851869 let obligation = Obligation :: new (
@@ -865,7 +883,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
865883 & e,
866884 ) ;
867885 }
868-
869886 self . check_op ( ops:: FnCallNonConst {
870887 caller,
871888 callee,
0 commit comments