@@ -53,7 +53,7 @@ pub fn trait_obligations<'a, 'tcx>(
5353 item : Option < & ' tcx hir:: Item > ,
5454) -> Vec < traits:: PredicateObligation < ' tcx > > {
5555 let mut wf = WfPredicates { infcx, param_env, body_id, span, out : vec ! [ ] , item } ;
56- wf. compute_trait_ref ( trait_ref, Elaborate :: All ) ;
56+ wf. compute_trait_ref ( trait_ref, Elaborate :: All , false ) ;
5757 wf. normalize ( )
5858}
5959
@@ -69,7 +69,7 @@ pub fn predicate_obligations<'a, 'tcx>(
6969 // (*) ok to skip binders, because wf code is prepared for it
7070 match * predicate {
7171 ty:: Predicate :: Trait ( ref t) => {
72- wf. compute_trait_ref ( & t. skip_binder ( ) . trait_ref , Elaborate :: None ) ; // (*)
72+ wf. compute_trait_ref ( & t. skip_binder ( ) . trait_ref , Elaborate :: None , false ) ; // (*)
7373 }
7474 ty:: Predicate :: RegionOutlives ( ..) => {
7575 }
@@ -163,14 +163,18 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
163163 }
164164
165165 /// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
166- fn compute_trait_ref ( & mut self , trait_ref : & ty:: TraitRef < ' tcx > , elaborate : Elaborate ) {
166+ fn compute_trait_ref (
167+ & mut self ,
168+ trait_ref : & ty:: TraitRef < ' tcx > ,
169+ elaborate : Elaborate ,
170+ is_proj : bool ,
171+ ) {
167172 let tcx = self . infcx . tcx ;
168- let obligations = self . nominal_obligations ( trait_ref. def_id , trait_ref. substs ) ;
169173
170174 let cause = self . cause ( traits:: MiscObligation ) ;
171175 let param_env = self . param_env ;
172176
173- let item = & self . item ;
177+ let item = self . item ;
174178 let extend_cause_with_original_assoc_item_obligation = |
175179 cause : & mut traits:: ObligationCause < ' _ > ,
176180 pred : & ty:: Predicate < ' _ > ,
@@ -313,26 +317,30 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
313317 }
314318 } ;
315319
316- if let Elaborate :: All = elaborate {
317- let trait_assoc_items = tcx. associated_items ( trait_ref. def_id ) ;
318-
319- let predicates = obligations. iter ( )
320- . map ( |obligation| obligation. predicate . clone ( ) )
321- . collect ( ) ;
322- let implied_obligations = traits:: elaborate_predicates ( tcx, predicates) ;
323- let implied_obligations = implied_obligations. map ( |pred| {
324- let mut cause = cause. clone ( ) ;
325- extend_cause_with_original_assoc_item_obligation (
326- & mut cause,
327- & pred,
328- trait_assoc_items. clone ( ) ,
329- ) ;
330- traits:: Obligation :: new ( cause, param_env, pred)
331- } ) ;
332- self . out . extend ( implied_obligations) ;
333- }
320+ if !is_proj {
321+ let obligations = self . nominal_obligations ( trait_ref. def_id , trait_ref. substs ) ;
322+
323+ if let Elaborate :: All = elaborate {
324+ let trait_assoc_items = tcx. associated_items ( trait_ref. def_id ) ;
325+
326+ let predicates = obligations. iter ( )
327+ . map ( |obligation| obligation. predicate . clone ( ) )
328+ . collect ( ) ;
329+ let implied_obligations = traits:: elaborate_predicates ( tcx, predicates) ;
330+ let implied_obligations = implied_obligations. map ( |pred| {
331+ let mut cause = cause. clone ( ) ;
332+ extend_cause_with_original_assoc_item_obligation (
333+ & mut cause,
334+ & pred,
335+ trait_assoc_items. clone ( ) ,
336+ ) ;
337+ traits:: Obligation :: new ( cause, param_env, pred)
338+ } ) ;
339+ self . out . extend ( implied_obligations) ;
340+ }
334341
335- self . out . extend ( obligations) ;
342+ self . out . extend ( obligations) ;
343+ }
336344
337345 self . out . extend ( trait_ref. substs . types ( )
338346 . filter ( |ty| !ty. has_escaping_bound_vars ( ) )
@@ -350,7 +358,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
350358 // WF and (b) the trait-ref holds. (It may also be
351359 // normalizable and be WF that way.)
352360 let trait_ref = data. trait_ref ( self . infcx . tcx ) ;
353- self . compute_trait_ref ( & trait_ref, Elaborate :: None ) ;
361+ self . compute_trait_ref ( & trait_ref, Elaborate :: None , true ) ;
354362
355363 if !data. has_escaping_bound_vars ( ) {
356364 let predicate = trait_ref. to_predicate ( ) ;
0 commit comments