@@ -6,9 +6,8 @@ use crate::errors;
66use rustc_ast:: util:: parser:: PREC_POSTFIX ;
77use rustc_errors:: { Applicability , Diagnostic , ErrorGuaranteed , StashKey } ;
88use rustc_hir as hir;
9- use rustc_hir:: def:: { self , CtorKind , DefKind , Namespace , Res } ;
9+ use rustc_hir:: def:: { self , CtorKind , Namespace , Res } ;
1010use rustc_hir:: def_id:: DefId ;
11- use rustc_hir:: HirId ;
1211use rustc_hir_analysis:: autoderef:: Autoderef ;
1312use rustc_infer:: {
1413 infer,
@@ -373,7 +372,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
373372 ) -> Ty < ' tcx > {
374373 let ( fn_sig, def_id) = match * callee_ty. kind ( ) {
375374 ty:: FnDef ( def_id, args) => {
376- self . enforce_context_effects ( call_expr. hir_id , call_expr . span , def_id, args) ;
375+ self . enforce_context_effects ( call_expr. span , def_id, args) ;
377376 let fn_sig = self . tcx . fn_sig ( def_id) . instantiate ( self . tcx , args) ;
378377
379378 // Unit testing: function items annotated with
@@ -770,7 +769,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
770769 #[ tracing:: instrument( level = "debug" , skip( self , span) ) ]
771770 pub ( super ) fn enforce_context_effects (
772771 & self ,
773- call_expr_hir : HirId ,
774772 span : Span ,
775773 callee_did : DefId ,
776774 callee_args : GenericArgsRef < ' tcx > ,
@@ -781,38 +779,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
781779 let generics = tcx. generics_of ( callee_did) ;
782780 let Some ( host_effect_index) = generics. host_effect_index else { return } ;
783781
784- // if the callee does have the param, we need to equate the param to some const
785- // value no matter whether the effects feature is enabled in the local crate,
786- // because inference will fail if we don't.
787- let mut host_always_on =
788- !tcx. features ( ) . effects || tcx. sess . opts . unstable_opts . unleash_the_miri_inside_of_you ;
789-
790- // Compute the constness required by the context.
791- let context = tcx. hir ( ) . enclosing_body_owner ( call_expr_hir) ;
792- let const_context = tcx. hir ( ) . body_const_context ( context) ;
793-
794- let kind = tcx. def_kind ( context. to_def_id ( ) ) ;
795- debug_assert_ne ! ( kind, DefKind :: ConstParam ) ;
796-
797- if tcx. has_attr ( context. to_def_id ( ) , sym:: rustc_do_not_const_check) {
798- trace ! ( "do not const check this context" ) ;
799- host_always_on = true ;
800- }
801-
802- let effect = match const_context {
803- _ if host_always_on => tcx. consts . true_ ,
804- Some ( hir:: ConstContext :: Static ( _) | hir:: ConstContext :: Const { .. } ) => {
805- tcx. consts . false_
806- }
807- Some ( hir:: ConstContext :: ConstFn ) => {
808- let host_idx = tcx
809- . generics_of ( context)
810- . host_effect_index
811- . expect ( "ConstContext::Maybe must have host effect param" ) ;
812- ty:: GenericArgs :: identity_for_item ( tcx, context) . const_at ( host_idx)
813- }
814- None => tcx. consts . true_ ,
815- } ;
782+ let effect = tcx. expected_const_effect_param_for_body ( self . body_id ) ;
816783
817784 trace ! ( ?effect, ?generics, ?callee_args) ;
818785
0 commit comments