@@ -2821,7 +2821,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28212821 // but has nested obligations which are unsatisfied.
28222822 for ( base_t, _) in self . autoderef ( base. span , base_t) . silence_errors ( ) {
28232823 if let Some ( ( _, index_ty, element_ty) ) =
2824- self . find_and_report_unsatisfied_index_impl ( expr . hir_id , base, base_t)
2824+ self . find_and_report_unsatisfied_index_impl ( base, base_t)
28252825 {
28262826 self . demand_coerce ( idx, idx_t, index_ty, None , AllowTwoPhase :: No ) ;
28272827 return element_ty;
@@ -2880,7 +2880,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
28802880 /// predicates cause this to be, so that the user can add them to fix their code.
28812881 fn find_and_report_unsatisfied_index_impl (
28822882 & self ,
2883- index_expr_hir_id : HirId ,
28842883 base_expr : & hir:: Expr < ' _ > ,
28852884 base_ty : Ty < ' tcx > ,
28862885 ) -> Option < ( ErrorGuaranteed , Ty < ' tcx > , Ty < ' tcx > ) > {
@@ -2913,13 +2912,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29132912 // in the first place.
29142913 ocx. register_obligations ( traits:: predicates_for_generics (
29152914 |idx, span| {
2916- traits:: ObligationCause :: new (
2917- base_expr. span ,
2918- self . body_id ,
2919- if span. is_dummy ( ) {
2920- traits:: ExprItemObligation ( impl_def_id, index_expr_hir_id, idx)
2921- } else {
2922- traits:: ExprBindingObligation ( impl_def_id, span, index_expr_hir_id, idx)
2915+ cause. clone ( ) . derived_cause (
2916+ ty:: Binder :: dummy ( ty:: TraitPredicate {
2917+ trait_ref : impl_trait_ref,
2918+ polarity : ty:: ImplPolarity :: Positive ,
2919+ constness : ty:: BoundConstness :: NotConst ,
2920+ } ) ,
2921+ |derived| {
2922+ traits:: ImplDerivedObligation ( Box :: new (
2923+ traits:: ImplDerivedObligationCause {
2924+ derived,
2925+ impl_or_alias_def_id : impl_def_id,
2926+ impl_def_predicate_index : Some ( idx) ,
2927+ span,
2928+ } ,
2929+ ) )
29232930 } ,
29242931 )
29252932 } ,
0 commit comments