@@ -7,8 +7,9 @@ use rustc_hir::lang_items::LangItem;
7
7
use rustc_middle:: ty:: subst:: { GenericArg , GenericArgKind , SubstsRef } ;
8
8
use rustc_middle:: ty:: { self , ToPredicate , Ty , TyCtxt , TypeFoldable , WithConstness } ;
9
9
use rustc_span:: Span ;
10
- use std:: rc:: Rc ;
11
10
11
+ use std:: iter;
12
+ use std:: rc:: Rc ;
12
13
/// Returns the set of obligations needed to make `arg` well-formed.
13
14
/// If `arg` contains unresolved inference variables, this may include
14
15
/// further WF obligations. However, if `arg` IS an unresolved
@@ -616,13 +617,24 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
616
617
def_id : DefId ,
617
618
substs : SubstsRef < ' tcx > ,
618
619
) -> 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
+
620
631
predicates
621
632
. predicates
622
633
. into_iter ( )
623
634
. 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) ) ;
626
638
traits:: Obligation :: new ( cause, self . param_env , pred)
627
639
} )
628
640
. filter ( |pred| !pred. has_escaping_bound_vars ( ) )
0 commit comments