about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_typeck/src/expr.rs14
-rw-r--r--tests/ui/indexing/point-at-index-for-obligation-failure.rs7
-rw-r--r--tests/ui/indexing/point-at-index-for-obligation-failure.stderr13
3 files changed, 22 insertions, 12 deletions
diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs
index 9f439a2b32a..7298e1e5702 100644
--- a/compiler/rustc_hir_typeck/src/expr.rs
+++ b/compiler/rustc_hir_typeck/src/expr.rs
@@ -2877,7 +2877,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(|errors| {
-                        self.point_at_index_if_possible(errors, idx.span)
+                        self.point_at_index(errors, idx.span)
                     });
                     element_ty
                 }
@@ -3036,18 +3036,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         .ok()
     }
 
-    fn point_at_index_if_possible(
-        &self,
-        errors: &mut Vec<traits::FulfillmentError<'tcx>>,
-        span: Span,
-    ) {
+    fn point_at_index(&self, errors: &mut Vec<traits::FulfillmentError<'tcx>>, span: Span) {
         for error in errors {
-            match error.obligation.predicate.kind().skip_binder() {
-                ty::PredicateKind::Clause(ty::ClauseKind::Trait(predicate))
-                    if self.tcx.is_diagnostic_item(sym::SliceIndex, predicate.trait_ref.def_id) => {
-                }
-                _ => continue,
-            }
             error.obligation.cause.span = span;
         }
     }
diff --git a/tests/ui/indexing/point-at-index-for-obligation-failure.rs b/tests/ui/indexing/point-at-index-for-obligation-failure.rs
new file mode 100644
index 00000000000..e9c429b53ce
--- /dev/null
+++ b/tests/ui/indexing/point-at-index-for-obligation-failure.rs
@@ -0,0 +1,7 @@
+fn main() {
+    let a = std::collections::HashMap::<String,String>::new();
+    let s = "hello";
+    let _b = a[
+        &s //~ ERROR E0277
+    ];
+}
diff --git a/tests/ui/indexing/point-at-index-for-obligation-failure.stderr b/tests/ui/indexing/point-at-index-for-obligation-failure.stderr
new file mode 100644
index 00000000000..3e2fbc2ab6f
--- /dev/null
+++ b/tests/ui/indexing/point-at-index-for-obligation-failure.stderr
@@ -0,0 +1,13 @@
+error[E0277]: the trait bound `String: Borrow<&str>` is not satisfied
+  --> $DIR/point-at-index-for-obligation-failure.rs:5:9
+   |
+LL |         &s
+   |         ^^ the trait `Borrow<&str>` is not implemented for `String`
+   |
+   = help: the trait `Borrow<str>` is implemented for `String`
+   = help: for that trait implementation, expected `str`, found `&str`
+   = note: required for `HashMap<String, String>` to implement `Index<&&str>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.