about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs4
-rw-r--r--compiler/rustc_hir/src/hir.rs9
2 files changed, 8 insertions, 5 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index b800e8d45d2..da58db57525 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -2120,7 +2120,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
                 let hir::ExprKind::Index(_, idx1, _) = parent.kind else { return };
                 let hir::Node::Expr(parent) = tcx.parent_hir_node(index2.hir_id) else { return };
                 let hir::ExprKind::Index(_, idx2, _) = parent.kind else { return };
-                if !idx1.equals(idx2) {
+                if !idx1.equivalent_for_indexing(idx2) {
                     err.help("use `.split_at_mut(position)` to obtain two mutable non-overlapping sub-slices");
                 }
                 return;
@@ -2146,7 +2146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
         let Some(index2) = self.find_expr(issued_span) else { return };
         let hir::Node::Expr(parent) = tcx.parent_hir_node(index2.hir_id) else { return };
         let hir::ExprKind::Index(_, idx2, _) = parent.kind else { return };
-        if idx1.equals(idx2) {
+        if idx1.equivalent_for_indexing(idx2) {
             // `let a = &mut foo[0]` and `let b = &mut foo[0]`? Don't mention `split_at_mut`
             return;
         }
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 1e66d42c227..1646ea50fb0 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -1815,7 +1815,7 @@ impl Expr<'_> {
     ///
     /// This is only used for diagnostics to see if we have things like `foo[i]` where `foo` is
     /// borrowed multiple times with `i`.
-    pub fn equals(&self, other: &Expr<'_>) -> bool {
+    pub fn equivalent_for_indexing(&self, other: &Expr<'_>) -> bool {
         match (self.kind, other.kind) {
             (ExprKind::Lit(lit1), ExprKind::Lit(lit2)) => lit1.node == lit2.node,
             (
@@ -1837,11 +1837,14 @@ impl Expr<'_> {
             | (
                 ExprKind::Struct(QPath::LangItem(LangItem::RangeFrom, _), [val1], None),
                 ExprKind::Struct(QPath::LangItem(LangItem::RangeFrom, _), [val2], None),
-            ) => val1.expr.equals(val2.expr),
+            ) => val1.expr.equivalent_for_indexing(val2.expr),
             (
                 ExprKind::Struct(QPath::LangItem(LangItem::Range, _), [val1, val3], None),
                 ExprKind::Struct(QPath::LangItem(LangItem::Range, _), [val2, val4], None),
-            ) => val1.expr.equals(val2.expr) && val3.expr.equals(val4.expr),
+            ) => {
+                val1.expr.equivalent_for_indexing(val2.expr)
+                    && val3.expr.equivalent_for_indexing(val4.expr)
+            }
             _ => false,
         }
     }