@@ -722,6 +722,32 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
722722 }
723723 } ;
724724
725+ // Check that all trait bounds that are marked as `~const` can be satisfied.
726+ //
727+ // Typeck only does a "non-const" check since it operates on HIR and cannot distinguish
728+ // which path expressions are getting called on and which path expressions are only used
729+ // as function pointers. This is required for correctness.
730+ let infcx = tcx. infer_ctxt ( ) . build ( ) ;
731+ let ocx = ObligationCtxt :: new ( & infcx) ;
732+
733+ let predicates = tcx. predicates_of ( callee) . instantiate ( tcx, substs) ;
734+ let cause = ObligationCause :: new (
735+ terminator. source_info . span ,
736+ self . body . source . def_id ( ) . expect_local ( ) ,
737+ ObligationCauseCode :: ItemObligation ( callee) ,
738+ ) ;
739+ let normalized_predicates = ocx. normalize ( & cause, param_env, predicates) ;
740+ ocx. register_obligations ( traits:: predicates_for_generics (
741+ |_, _| cause. clone ( ) ,
742+ self . param_env ,
743+ normalized_predicates,
744+ ) ) ;
745+
746+ let errors = ocx. select_all_or_error ( ) ;
747+ if !errors. is_empty ( ) {
748+ infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors) ;
749+ }
750+
725751 // Attempting to call a trait method?
726752 if let Some ( trait_id) = tcx. trait_of_item ( callee) {
727753 trace ! ( "attempting to call a trait method" ) ;
@@ -749,31 +775,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
749775 selcx. select ( & obligation)
750776 } ;
751777
752- // do a well-formedness check on the trait method being called. This is because typeck only does a
753- // "non-const" check. This is required for correctness here.
754- {
755- let infcx = tcx. infer_ctxt ( ) . build ( ) ;
756- let ocx = ObligationCtxt :: new ( & infcx) ;
757-
758- let predicates = tcx. predicates_of ( callee) . instantiate ( tcx, substs) ;
759- let cause = ObligationCause :: new (
760- terminator. source_info . span ,
761- self . body . source . def_id ( ) . expect_local ( ) ,
762- ObligationCauseCode :: ItemObligation ( callee) ,
763- ) ;
764- let normalized_predicates = ocx. normalize ( & cause, param_env, predicates) ;
765- ocx. register_obligations ( traits:: predicates_for_generics (
766- |_, _| cause. clone ( ) ,
767- self . param_env ,
768- normalized_predicates,
769- ) ) ;
770-
771- let errors = ocx. select_all_or_error ( ) ;
772- if !errors. is_empty ( ) {
773- infcx. err_ctxt ( ) . report_fulfillment_errors ( & errors) ;
774- }
775- }
776-
777778 match implsrc {
778779 Ok ( Some ( ImplSource :: Param ( _, ty:: BoundConstness :: ConstIfConst ) ) ) => {
779780 debug ! (
0 commit comments