about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-06-02 02:19:32 +0000
committerMichael Goulet <michael@errs.io>2025-06-02 02:19:35 +0000
commit4a803d26ead24aa9cfdba3717fe2e9ffdc41f0e0 (patch)
treeceadeb56d1110cfb3a05137e0adb565fa591add6
parentd2d0f62f783b0640f7ededb25776a724031cebf7 (diff)
downloadrust-4a803d26ead24aa9cfdba3717fe2e9ffdc41f0e0.tar.gz
rust-4a803d26ead24aa9cfdba3717fe2e9ffdc41f0e0.zip
Suppress redundant error
-rw-r--r--compiler/rustc_hir/src/hir.rs7
-rw-r--r--tests/ui/destructuring-assignment/bad-let-in-destructure.rs1
-rw-r--r--tests/ui/destructuring-assignment/bad-let-in-destructure.stderr13
3 files changed, 7 insertions, 14 deletions
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index f63ab303689..ea195fb2157 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -2370,6 +2370,10 @@ impl Expr<'_> {
             // Lang item paths cannot currently be local variables or statics.
             ExprKind::Path(QPath::LangItem(..)) => false,
 
+            // Suppress errors for bad expressions.
+            ExprKind::Err(_guar)
+            | ExprKind::Let(&LetExpr { recovered: ast::Recovered::Yes(_guar), .. }) => true,
+
             // Partially qualified paths in expressions can only legally
             // refer to associated items which are always rvalues.
             ExprKind::Path(QPath::TypeRelative(..))
@@ -2401,8 +2405,7 @@ impl Expr<'_> {
             | ExprKind::Binary(..)
             | ExprKind::Yield(..)
             | ExprKind::Cast(..)
-            | ExprKind::DropTemps(..)
-            | ExprKind::Err(_) => false,
+            | ExprKind::DropTemps(..) => false,
         }
     }
 
diff --git a/tests/ui/destructuring-assignment/bad-let-in-destructure.rs b/tests/ui/destructuring-assignment/bad-let-in-destructure.rs
index 222557a8975..70a0403fc38 100644
--- a/tests/ui/destructuring-assignment/bad-let-in-destructure.rs
+++ b/tests/ui/destructuring-assignment/bad-let-in-destructure.rs
@@ -10,5 +10,4 @@ fn main() {
   // in the AST, the `let` expression was visited first.
   (let x = 1,) = x;
   //~^ ERROR expected expression, found `let` statement
-  //~| ERROR invalid left-hand side of assignment
 }
diff --git a/tests/ui/destructuring-assignment/bad-let-in-destructure.stderr b/tests/ui/destructuring-assignment/bad-let-in-destructure.stderr
index 277405539d8..622d714ba2f 100644
--- a/tests/ui/destructuring-assignment/bad-let-in-destructure.stderr
+++ b/tests/ui/destructuring-assignment/bad-let-in-destructure.stderr
@@ -1,19 +1,10 @@
 error: expected expression, found `let` statement
-  --> $DIR/bad-let-in-destructure.rs:10:4
+  --> $DIR/bad-let-in-destructure.rs:11:4
    |
 LL |   (let x = 1,) = x;
    |    ^^^
    |
    = note: only supported directly in conditions of `if` and `while` expressions
 
-error[E0070]: invalid left-hand side of assignment
-  --> $DIR/bad-let-in-destructure.rs:10:16
-   |
-LL |   (let x = 1,) = x;
-   |    ---------   ^
-   |    |
-   |    cannot assign to this expression
-
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0070`.