@@ -53,7 +53,7 @@ pub fn trait_obligations<'a, 'tcx>(
53
53
item : Option < & ' tcx hir:: Item > ,
54
54
) -> Vec < traits:: PredicateObligation < ' tcx > > {
55
55
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 ) ;
57
57
wf. normalize ( )
58
58
}
59
59
@@ -69,7 +69,7 @@ pub fn predicate_obligations<'a, 'tcx>(
69
69
// (*) ok to skip binders, because wf code is prepared for it
70
70
match * predicate {
71
71
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 ) ; // (*)
73
73
}
74
74
ty:: Predicate :: RegionOutlives ( ..) => {
75
75
}
@@ -163,14 +163,18 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
163
163
}
164
164
165
165
/// 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
+ ) {
167
172
let tcx = self . infcx . tcx ;
168
- let obligations = self . nominal_obligations ( trait_ref. def_id , trait_ref. substs ) ;
169
173
170
174
let cause = self . cause ( traits:: MiscObligation ) ;
171
175
let param_env = self . param_env ;
172
176
173
- let item = & self . item ;
177
+ let item = self . item ;
174
178
let extend_cause_with_original_assoc_item_obligation = |
175
179
cause : & mut traits:: ObligationCause < ' _ > ,
176
180
pred : & ty:: Predicate < ' _ > ,
@@ -313,26 +317,30 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
313
317
}
314
318
} ;
315
319
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
+ }
334
341
335
- self . out . extend ( obligations) ;
342
+ self . out . extend ( obligations) ;
343
+ }
336
344
337
345
self . out . extend ( trait_ref. substs . types ( )
338
346
. filter ( |ty| !ty. has_escaping_bound_vars ( ) )
@@ -350,7 +358,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
350
358
// WF and (b) the trait-ref holds. (It may also be
351
359
// normalizable and be WF that way.)
352
360
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 ) ;
354
362
355
363
if !data. has_escaping_bound_vars ( ) {
356
364
let predicate = trait_ref. to_predicate ( ) ;
0 commit comments