about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-09-03 19:12:44 +0000
committerMichael Goulet <michael@errs.io>2022-09-03 19:12:44 +0000
commit771456264b4219ea5ef5bce15cc74c5901afe820 (patch)
treedbf8ff86a5733d9d806b045a981edc9157b6c58b
parentae0030beb0398cabb2626fe326d6b2e8286c70b9 (diff)
downloadrust-771456264b4219ea5ef5bce15cc74c5901afe820.tar.gz
rust-771456264b4219ea5ef5bce15cc74c5901afe820.zip
Don't delay invalid lhs bug unless we know it'll be replaced by one in check_overloaded_binop
-rw-r--r--compiler/rustc_typeck/src/check/op.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs
index 952086e898f..d51dccd1af5 100644
--- a/compiler/rustc_typeck/src/check/op.rs
+++ b/compiler/rustc_typeck/src/check/op.rs
@@ -57,9 +57,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     )
                     .is_ok()
                 {
-                    // Suppress this error, since we already emitted
-                    // a deref suggestion in check_overloaded_binop
-                    err.downgrade_to_delayed_bug();
+                    // If LHS += RHS is an error, but *LHS += RHS is successful, then we will have
+                    // emitted a better suggestion during error handling in check_overloaded_binop.
+                    if self
+                        .lookup_op_method(
+                            lhs_ty,
+                            Some(rhs_ty),
+                            Some(rhs),
+                            Op::Binary(op, IsAssign::Yes),
+                            expected,
+                        )
+                        .is_err()
+                    {
+                        err.downgrade_to_delayed_bug();
+                    }
                 }
             }
         });