@@ -2822,7 +2822,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2822
2822
// but has nested obligations which are unsatisfied.
2823
2823
for ( base_t, _) in self . autoderef ( base. span , base_t) . silence_errors ( ) {
2824
2824
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)
2826
2826
{
2827
2827
self . demand_coerce ( idx, idx_t, index_ty, None , AllowTwoPhase :: No ) ;
2828
2828
return element_ty;
@@ -2881,7 +2881,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2881
2881
/// predicates cause this to be, so that the user can add them to fix their code.
2882
2882
fn find_and_report_unsatisfied_index_impl (
2883
2883
& self ,
2884
- index_expr_hir_id : HirId ,
2885
2884
base_expr : & hir:: Expr < ' _ > ,
2886
2885
base_ty : Ty < ' tcx > ,
2887
2886
) -> Option < ( ErrorGuaranteed , Ty < ' tcx > , Ty < ' tcx > ) > {
@@ -2914,13 +2913,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2914
2913
// in the first place.
2915
2914
ocx. register_obligations ( traits:: predicates_for_generics (
2916
2915
|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
+ ) )
2924
2931
} ,
2925
2932
)
2926
2933
} ,
0 commit comments