@@ -85,7 +85,7 @@ pub fn trait_obligations<'a, 'tcx>(
85
85
infcx : & InferCtxt < ' a , ' tcx > ,
86
86
param_env : ty:: ParamEnv < ' tcx > ,
87
87
body_id : hir:: HirId ,
88
- trait_ref : & ty:: TraitRef < ' tcx > ,
88
+ trait_pred : & ty:: TraitPredicate < ' tcx > ,
89
89
span : Span ,
90
90
item : & ' tcx hir:: Item < ' tcx > ,
91
91
) -> Vec < traits:: PredicateObligation < ' tcx > > {
@@ -98,7 +98,7 @@ pub fn trait_obligations<'a, 'tcx>(
98
98
recursion_depth : 0 ,
99
99
item : Some ( item) ,
100
100
} ;
101
- wf. compute_trait_ref ( trait_ref , Elaborate :: All ) ;
101
+ wf. compute_trait_pred ( trait_pred , Elaborate :: All ) ;
102
102
debug ! ( obligations = ?wf. out) ;
103
103
wf. normalize ( infcx)
104
104
}
@@ -123,7 +123,7 @@ pub fn predicate_obligations<'a, 'tcx>(
123
123
// It's ok to skip the binder here because wf code is prepared for it
124
124
match predicate. kind ( ) . skip_binder ( ) {
125
125
ty:: PredicateKind :: Trait ( t) => {
126
- wf. compute_trait_ref ( & t. trait_ref , Elaborate :: None ) ;
126
+ wf. compute_trait_pred ( & t, Elaborate :: None ) ;
127
127
}
128
128
ty:: PredicateKind :: RegionOutlives ( ..) => { }
129
129
ty:: PredicateKind :: TypeOutlives ( ty:: OutlivesPredicate ( ty, _reg) ) => {
@@ -301,11 +301,18 @@ impl<'tcx> WfPredicates<'tcx> {
301
301
}
302
302
303
303
/// 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 ) {
305
305
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 ;
307
307
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) ;
309
316
let param_env = self . param_env ;
310
317
let depth = self . recursion_depth ;
311
318
@@ -685,10 +692,11 @@ impl<'tcx> WfPredicates<'tcx> {
685
692
}
686
693
687
694
#[ instrument( level = "debug" , skip( self ) ) ]
688
- fn nominal_obligations (
695
+ fn nominal_obligations_inner (
689
696
& mut self ,
690
697
def_id : DefId ,
691
698
substs : SubstsRef < ' tcx > ,
699
+ remap_constness : bool ,
692
700
) -> Vec < traits:: PredicateObligation < ' tcx > > {
693
701
let predicates = self . tcx . predicates_of ( def_id) ;
694
702
let mut origins = vec ! [ def_id; predicates. predicates. len( ) ] ;
@@ -703,19 +711,38 @@ impl<'tcx> WfPredicates<'tcx> {
703
711
debug_assert_eq ! ( predicates. predicates. len( ) , origins. len( ) ) ;
704
712
705
713
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) | {
707
715
let code = if span. is_dummy ( ) {
708
716
traits:: MiscObligation
709
717
} else {
710
718
traits:: BindingObligation ( origin_def_id, span)
711
719
} ;
712
720
let cause = self . cause ( code) ;
721
+ if remap_constness {
722
+ pred = pred. without_const ( self . tcx ) ;
723
+ }
713
724
traits:: Obligation :: with_depth ( cause, self . recursion_depth , self . param_env , pred)
714
725
} )
715
726
. filter ( |pred| !pred. has_escaping_bound_vars ( ) )
716
727
. collect ( )
717
728
}
718
729
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
+
719
746
fn from_object_ty (
720
747
& mut self ,
721
748
ty : Ty < ' tcx > ,
0 commit comments