@@ -179,8 +179,46 @@ impl<'tcx> Elaborator<'tcx> {
179
179
// Currently, we do not "elaborate" predicates like `X -> Y`,
180
180
// though conceivably we might.
181
181
}
182
- ty:: PredicateKind :: Projection ( ..) => {
183
- // Nothing to elaborate in a projection predicate.
182
+ ty:: PredicateKind :: Projection ( projection_pred) => {
183
+ let predicates = tcx. explicit_item_bounds ( projection_pred. projection_ty . item_def_id ) ;
184
+
185
+ debug ! ( ?projection_pred, ?predicates) ;
186
+ //dbg!(&predicates);
187
+
188
+ use crate :: rustc_middle:: ty:: subst:: Subst ;
189
+ let obligations = predicates. iter ( ) . filter_map ( |& ( pred, _) | {
190
+ let predicate = tcx. mk_predicate ( bound_predicate. map_bound ( |_| pred. kind ( ) . skip_binder ( ) . subst ( tcx, projection_pred. projection_ty . substs ) ) ) ;
191
+
192
+ let predicate = match predicate. kind ( ) . skip_binder ( ) {
193
+ ty:: PredicateKind :: Trait ( trait_predicate) => {
194
+ let mut substs: smallvec:: SmallVec < [ _ ; 4 ] > = trait_predicate. trait_ref . substs . iter ( ) . collect ( ) ;
195
+ substs[ 0 ] = projection_pred. ty . into ( ) ;
196
+ let substs = tcx. mk_substs ( substs. into_iter ( ) ) ;
197
+ let trait_predicate = ty:: TraitPredicate {
198
+ constness : trait_predicate. constness ,
199
+ polarity : trait_predicate. polarity ,
200
+ trait_ref : ty:: TraitRef {
201
+ def_id : trait_predicate. def_id ( ) ,
202
+ substs,
203
+ } ,
204
+ } ;
205
+ tcx. mk_predicate ( predicate. kind ( ) . map_bound ( |_| ty:: PredicateKind :: Trait ( trait_predicate) ) )
206
+ }
207
+ ty:: PredicateKind :: Projection ( _projection_predicate) => return None ,
208
+ _ => return None ,
209
+ } ;
210
+ //dbg!(projection_pred, predicate, bound_predicate);
211
+ Some ( predicate_obligation (
212
+ predicate,
213
+ obligation. param_env ,
214
+ obligation. cause . clone ( ) ,
215
+ ) )
216
+ } ) ;
217
+
218
+ let visited = & mut self . visited ;
219
+ let obligations = obligations. filter ( |o| visited. insert ( o. predicate ) ) ;
220
+
221
+ self . stack . extend ( obligations) ;
184
222
}
185
223
ty:: PredicateKind :: ClosureKind ( ..) => {
186
224
// Nothing to elaborate when waiting for a closure's kind to be inferred.
0 commit comments