Skip to content

Commit 06f89b7

Browse files
committed
implement point_at_index_if_possible
1 parent 1d4ddab commit 06f89b7

File tree

1 file changed

+17
-11
lines changed
  • compiler/rustc_typeck/src/check

1 file changed

+17
-11
lines changed

compiler/rustc_typeck/src/check/expr.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,17 +2649,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26492649
// two-phase not needed because index_ty is never mutable
26502650
self.demand_coerce(idx, idx_t, index_ty, None, AllowTwoPhase::No);
26512651
self.select_obligations_where_possible(false, |errors| {
2652-
for error in errors {
2653-
match error.obligation.predicate.kind().skip_binder() {
2654-
ty::PredicateKind::Trait(predicate)
2655-
if self.tcx.is_diagnostic_item(
2656-
sym::SliceIndex,
2657-
predicate.trait_ref.def_id,
2658-
) => {}
2659-
_ => continue,
2660-
}
2661-
error.obligation.cause.span = idx.span;
2662-
}
2652+
self.point_at_index_if_possible(errors, idx.span)
26632653
});
26642654
element_ty
26652655
}
@@ -2704,6 +2694,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27042694
}
27052695
}
27062696

2697+
fn point_at_index_if_possible(
2698+
&self,
2699+
errors: &mut Vec<traits::FulfillmentError<'tcx>>,
2700+
span: Span,
2701+
) {
2702+
for error in errors {
2703+
match error.obligation.predicate.kind().skip_binder() {
2704+
ty::PredicateKind::Trait(predicate)
2705+
if self.tcx.is_diagnostic_item(sym::SliceIndex, predicate.trait_ref.def_id) => {
2706+
}
2707+
_ => continue,
2708+
}
2709+
error.obligation.cause.span = span;
2710+
}
2711+
}
2712+
27072713
fn check_expr_yield(
27082714
&self,
27092715
value: &'tcx hir::Expr<'tcx>,

0 commit comments

Comments
 (0)