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