about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTakayuki Maeda <takoyaki0316@gmail.com>2022-07-29 14:12:17 +0900
committerTakayuki Maeda <takoyaki0316@gmail.com>2022-07-29 14:12:17 +0900
commit06f89b7924af4657e847742bf0e40eafaaee52f9 (patch)
tree9c10a5c6d96a0061adabf443b0f5d7e4e16624ba
parent1d4ddab1bf5c523bdf6e3b7e9cff3c3224c6ed04 (diff)
downloadrust-06f89b7924af4657e847742bf0e40eafaaee52f9.tar.gz
rust-06f89b7924af4657e847742bf0e40eafaaee52f9.zip
implement `point_at_index_if_possible`
-rw-r--r--compiler/rustc_typeck/src/check/expr.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs
index 4c0a2bd9199..b2a5c055e46 100644
--- a/compiler/rustc_typeck/src/check/expr.rs
+++ b/compiler/rustc_typeck/src/check/expr.rs
@@ -2649,17 +2649,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     // two-phase not needed because index_ty is never mutable
                     self.demand_coerce(idx, idx_t, index_ty, None, AllowTwoPhase::No);
                     self.select_obligations_where_possible(false, |errors| {
-                        for error in errors {
-                            match error.obligation.predicate.kind().skip_binder() {
-                                ty::PredicateKind::Trait(predicate)
-                                    if self.tcx.is_diagnostic_item(
-                                        sym::SliceIndex,
-                                        predicate.trait_ref.def_id,
-                                    ) => {}
-                                _ => continue,
-                            }
-                            error.obligation.cause.span = idx.span;
-                        }
+                        self.point_at_index_if_possible(errors, idx.span)
                     });
                     element_ty
                 }
@@ -2704,6 +2694,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         }
     }
 
+    fn point_at_index_if_possible(
+        &self,
+        errors: &mut Vec<traits::FulfillmentError<'tcx>>,
+        span: Span,
+    ) {
+        for error in errors {
+            match error.obligation.predicate.kind().skip_binder() {
+                ty::PredicateKind::Trait(predicate)
+                    if self.tcx.is_diagnostic_item(sym::SliceIndex, predicate.trait_ref.def_id) => {
+                }
+                _ => continue,
+            }
+            error.obligation.cause.span = span;
+        }
+    }
+
     fn check_expr_yield(
         &self,
         value: &'tcx hir::Expr<'tcx>,