@@ -7,8 +7,9 @@ use rustc_hir::lang_items::LangItem;
77use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , SubstsRef } ;
88use rustc_middle:: ty:: { self , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness } ;
99use rustc_span:: Span ;
10- use std:: rc:: Rc ;
1110
11+ use std:: iter;
12+ use std:: rc:: Rc ;
1213/// Returns the set of obligations needed to make `arg` well-formed.
1314/// If `arg` contains unresolved inference variables, this may include
1415/// further WF obligations. However, if `arg` IS an unresolved
@@ -616,13 +617,24 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
616617 def_id : DefId ,
617618 substs : SubstsRef < ' tcx > ,
618619 ) -> Vec < traits:: PredicateObligation < ' tcx > > {
619- let predicates = self . infcx . tcx . predicates_of ( def_id) . instantiate ( self . infcx . tcx , substs) ;
620+ let predicates = self . infcx . tcx . predicates_of ( def_id) ;
621+ let mut origins = vec ! [ def_id; predicates. predicates. len( ) ] ;
622+ let mut head = predicates;
623+ while let Some ( parent) = head. parent {
624+ head = self . infcx . tcx . predicates_of ( parent) ;
625+ origins. extend ( iter:: repeat ( parent) . take ( head. predicates . len ( ) ) ) ;
626+ }
627+
628+ let predicates = predicates. instantiate ( self . infcx . tcx , substs) ;
629+ debug_assert_eq ! ( predicates. predicates. len( ) , origins. len( ) ) ;
630+
620631 predicates
621632 . predicates
622633 . into_iter ( )
623634 . zip ( predicates. spans . into_iter ( ) )
624- . map ( |( pred, span) | {
625- let cause = self . cause ( traits:: BindingObligation ( def_id, span) ) ;
635+ . zip ( origins. into_iter ( ) . rev ( ) )
636+ . map ( |( ( pred, span) , origin_def_id) | {
637+ let cause = self . cause ( traits:: BindingObligation ( origin_def_id, span) ) ;
626638 traits:: Obligation :: new ( cause, self . param_env , pred)
627639 } )
628640 . filter ( |pred| !pred. has_escaping_bound_vars ( ) )
0 commit comments