@@ -85,7 +85,7 @@ pub fn trait_obligations<'a, 'tcx>(
8585 infcx : & InferCtxt < ' a , ' tcx > ,
8686 param_env : ty:: ParamEnv < ' tcx > ,
8787 body_id : hir:: HirId ,
88- trait_ref : & ty:: TraitRef < ' tcx > ,
88+ trait_pred : & ty:: TraitPredicate < ' tcx > ,
8989 span : Span ,
9090 item : & ' tcx hir:: Item < ' tcx > ,
9191) -> Vec < traits:: PredicateObligation < ' tcx > > {
@@ -98,7 +98,7 @@ pub fn trait_obligations<'a, 'tcx>(
9898 recursion_depth : 0 ,
9999 item : Some ( item) ,
100100 } ;
101- wf. compute_trait_ref ( trait_ref , Elaborate :: All ) ;
101+ wf. compute_trait_pred ( trait_pred , Elaborate :: All ) ;
102102 debug ! ( obligations = ?wf. out) ;
103103 wf. normalize ( infcx)
104104}
@@ -123,7 +123,7 @@ pub fn predicate_obligations<'a, 'tcx>(
123123 // It's ok to skip the binder here because wf code is prepared for it
124124 match predicate. kind ( ) . skip_binder ( ) {
125125 ty:: PredicateKind :: Trait ( t) => {
126- wf. compute_trait_ref ( & t. trait_ref , Elaborate :: None ) ;
126+ wf. compute_trait_pred ( & t, Elaborate :: None ) ;
127127 }
128128 ty:: PredicateKind :: RegionOutlives ( ..) => { }
129129 ty:: PredicateKind :: TypeOutlives ( ty:: OutlivesPredicate ( ty, _reg) ) => {
@@ -301,11 +301,18 @@ impl<'tcx> WfPredicates<'tcx> {
301301 }
302302
303303 /// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
304- fn compute_trait_ref ( & mut self , trait_ref : & ty:: TraitRef < ' tcx > , elaborate : Elaborate ) {
304+ fn compute_trait_pred ( & mut self , trait_pred : & ty:: TraitPredicate < ' tcx > , elaborate : Elaborate ) {
305305 let tcx = self . tcx ;
306- let obligations = self . nominal_obligations ( trait_ref. def_id , trait_ref . substs ) ;
306+ let trait_ref = & trait_pred . trait_ref ;
307307
308- debug ! ( "compute_trait_ref obligations {:?}" , obligations) ;
308+ // if the trait predicate is not const, the wf obligations should not be const as well.
309+ let obligations = if trait_pred. constness == ty:: BoundConstness :: NotConst {
310+ self . nominal_obligations_without_const ( trait_ref. def_id , trait_ref. substs )
311+ } else {
312+ self . nominal_obligations ( trait_ref. def_id , trait_ref. substs )
313+ } ;
314+
315+ debug ! ( "compute_trait_pred obligations {:?}" , obligations) ;
309316 let param_env = self . param_env ;
310317 let depth = self . recursion_depth ;
311318
@@ -685,10 +692,11 @@ impl<'tcx> WfPredicates<'tcx> {
685692 }
686693
687694 #[ instrument( level = "debug" , skip( self ) ) ]
688- fn nominal_obligations (
695+ fn nominal_obligations_inner (
689696 & mut self ,
690697 def_id : DefId ,
691698 substs : SubstsRef < ' tcx > ,
699+ remap_constness : bool ,
692700 ) -> Vec < traits:: PredicateObligation < ' tcx > > {
693701 let predicates = self . tcx . predicates_of ( def_id) ;
694702 let mut origins = vec ! [ def_id; predicates. predicates. len( ) ] ;
@@ -703,19 +711,38 @@ impl<'tcx> WfPredicates<'tcx> {
703711 debug_assert_eq ! ( predicates. predicates. len( ) , origins. len( ) ) ;
704712
705713 iter:: zip ( iter:: zip ( predicates. predicates , predicates. spans ) , origins. into_iter ( ) . rev ( ) )
706- . map ( |( ( pred, span) , origin_def_id) | {
714+ . map ( |( ( mut pred, span) , origin_def_id) | {
707715 let code = if span. is_dummy ( ) {
708716 traits:: MiscObligation
709717 } else {
710718 traits:: BindingObligation ( origin_def_id, span)
711719 } ;
712720 let cause = self . cause ( code) ;
721+ if remap_constness {
722+ pred = pred. without_const ( self . tcx ) ;
723+ }
713724 traits:: Obligation :: with_depth ( cause, self . recursion_depth , self . param_env , pred)
714725 } )
715726 . filter ( |pred| !pred. has_escaping_bound_vars ( ) )
716727 . collect ( )
717728 }
718729
730+ fn nominal_obligations (
731+ & mut self ,
732+ def_id : DefId ,
733+ substs : SubstsRef < ' tcx > ,
734+ ) -> Vec < traits:: PredicateObligation < ' tcx > > {
735+ self . nominal_obligations_inner ( def_id, substs, false )
736+ }
737+
738+ fn nominal_obligations_without_const (
739+ & mut self ,
740+ def_id : DefId ,
741+ substs : SubstsRef < ' tcx > ,
742+ ) -> Vec < traits:: PredicateObligation < ' tcx > > {
743+ self . nominal_obligations_inner ( def_id, substs, true )
744+ }
745+
719746 fn from_object_ty (
720747 & mut self ,
721748 ty : Ty < ' tcx > ,
0 commit comments