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