about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShoyu Vanilla <modulo641@gmail.com>2024-08-01 02:51:33 +0900
committerShoyu Vanilla <modulo641@gmail.com>2024-08-01 02:51:33 +0900
commit086065e56b83e54f1236be0c69fadd613e7363a8 (patch)
tree918b917af71cca7fb44575d5a150aaa75f10842d
parent8b14b743f990d300995f0b1e7147f50512270af7 (diff)
Prevent redundant obigation push for assignee exprs
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/mutability.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/mutability.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/mutability.rs
index fbc7570c742..66267e08db6 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/mutability.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/mutability.rs
@@ -104,7 +104,7 @@ impl InferenceContext<'_> {
             Expr::RecordLit { path: _, fields, spread, ellipsis: _, is_assignee_expr: _ } => {
                 self.infer_mut_not_expr_iter(fields.iter().map(|it| it.expr).chain(*spread))
             }
-            &Expr::Index { base, index, is_assignee_expr: _ } => {
+            &Expr::Index { base, index, is_assignee_expr } => {
                 if mutability == Mutability::Mut {
                     if let Some((f, _)) = self.result.method_resolutions.get_mut(&tgt_expr) {
                         if let Some(index_trait) = self
@@ -129,12 +129,16 @@ impl InferenceContext<'_> {
                                     target,
                                 }) = base_adjustments
                                 {
-                                    *mutability = Mutability::Mut;
-                                    if let TyKind::Ref(_, _, ty) = target.kind(Interner) {
-                                        base_ty = Some(ty.clone());
+                                    // For assignee exprs `IndexMut` obiligations are already applied
+                                    if !is_assignee_expr {
+                                        if let TyKind::Ref(_, _, ty) = target.kind(Interner) {
+                                            base_ty = Some(ty.clone());
+                                        }
                                     }
+                                    *mutability = Mutability::Mut;
                                 }
 
+                                // Apply `IndexMut` obligation for non-assignee expr
                                 if let Some(base_ty) = base_ty {
                                     let index_ty =
                                         if let Some(ty) = self.result.type_of_expr.get(index) {