From 4a803d26ead24aa9cfdba3717fe2e9ffdc41f0e0 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 2 Jun 2025 02:19:32 +0000 Subject: [PATCH] Suppress redundant error --- compiler/rustc_hir/src/hir.rs | 7 +++++-- .../bad-let-in-destructure.rs | 1 - .../bad-let-in-destructure.stderr | 13 ++----------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index f63ab3036891..ea195fb2157b 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 222557a8975d..70a0403fc38c 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 277405539d8f..622d714ba2fd 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 1 previous error -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0070`.