Skip to content

Commit 4a803d2

Browse files
Suppress redundant error
1 parent d2d0f62 commit 4a803d2

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,10 @@ impl Expr<'_> {
23702370
// Lang item paths cannot currently be local variables or statics.
23712371
ExprKind::Path(QPath::LangItem(..)) => false,
23722372

2373+
// Suppress errors for bad expressions.
2374+
ExprKind::Err(_guar)
2375+
| ExprKind::Let(&LetExpr { recovered: ast::Recovered::Yes(_guar), .. }) => true,
2376+
23732377
// Partially qualified paths in expressions can only legally
23742378
// refer to associated items which are always rvalues.
23752379
ExprKind::Path(QPath::TypeRelative(..))
@@ -2401,8 +2405,7 @@ impl Expr<'_> {
24012405
| ExprKind::Binary(..)
24022406
| ExprKind::Yield(..)
24032407
| ExprKind::Cast(..)
2404-
| ExprKind::DropTemps(..)
2405-
| ExprKind::Err(_) => false,
2408+
| ExprKind::DropTemps(..) => false,
24062409
}
24072410
}
24082411

tests/ui/destructuring-assignment/bad-let-in-destructure.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ fn main() {
1010
// in the AST, the `let` expression was visited first.
1111
(let x = 1,) = x;
1212
//~^ ERROR expected expression, found `let` statement
13-
//~| ERROR invalid left-hand side of assignment
1413
}
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
error: expected expression, found `let` statement
2-
--> $DIR/bad-let-in-destructure.rs:10:4
2+
--> $DIR/bad-let-in-destructure.rs:11:4
33
|
44
LL | (let x = 1,) = x;
55
| ^^^
66
|
77
= note: only supported directly in conditions of `if` and `while` expressions
88

9-
error[E0070]: invalid left-hand side of assignment
10-
--> $DIR/bad-let-in-destructure.rs:10:16
11-
|
12-
LL | (let x = 1,) = x;
13-
| --------- ^
14-
| |
15-
| cannot assign to this expression
16-
17-
error: aborting due to 2 previous errors
9+
error: aborting due to 1 previous error
1810

19-
For more information about this error, try `rustc --explain E0070`.

0 commit comments

Comments
 (0)