Suppress redundant error

This commit is contained in:
Michael Goulet 2025-06-02 02:19:32 +00:00
parent d2d0f62f78
commit 4a803d26ea
3 changed files with 7 additions and 14 deletions

View file

@ -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,
}
}

View file

@ -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
}

View file

@ -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`.