Repository navigation
Let chain error message with || is confusing and verbose #140263
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-let-chainsArea: let chains (if-let, while-let, ...)Area: let chains (if-let, while-let, ...)D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn main() {
if let true = true || false {}
}Current output
error: expected expression, found `let` statement
--> src/main.rs:6:8
|
6 | if let true = true || false {}
| ^^^^^^^^^^^^^^^
|
= note: only supported directly in conditions of `if` and `while` expressions
note: `||` operators are not supported in let chain expressions
--> src/main.rs:6:24
|
6 | if let true = true || false {}
| ^^Desired output
error: `||` in an `if` expression with `let` is not allowed
--> src/main.rs:2:17
|
2 | if let true = true || false {}
| ^^
|Rationale and extra context
The current error message has several confusing factors:
- The primary error message
expected expression, found `let` statementwhich is confusing. I suppose this is technically correct (letis not allowed in anifwith a||), but muddles the problem. There's also the confusion of using the term`let` statement`, where the term "statement"is confusing here. - The note
only supported directly in conditions of `if` and `while` expressionsis confusing, since we are in anifexpression. - The final note of
note: `||` operators are not supported in let chain expressionsshows the actual problem, but it is lost in a sea of other text.
Other cases
Rust Version
rustc 1.88.0-nightly (df35ff6c3 2025-04-23)
binary: rustc
commit-hash: df35ff6c354f1f1fbf430b84e7dea37dfe997f34
commit-date: 2025-04-23
host: aarch64-apple-darwin
release: 1.88.0-nightly
LLVM version: 20.1.2Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-let-chainsArea: let chains (if-let, while-let, ...)Area: let chains (if-let, while-let, ...)D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
traviscross commentedon Apr 24, 2025
cc @est31 @fee1-dead
Kivooeo commentedon Apr 24, 2025
@rustbot claim
est31 commentedon Apr 24, 2025
Agree that it could be improved. As you say, it's technically correct (explained how
||in&&chains plays together with precedence in more detail here), but the error is too close to the "language level" instead of the level the user is at.Fine with dropping "statement" but the error message should not call it an expression in any case because the let chains RFC didn't make
letinto an expression in the general sense.It's definitely implemented that way in the compiler AST, but compiler behaviour should follow the language level, including error message, even if colloquial understanding sees
letinsidewhileorifas an "expression".est31 commentedon Apr 24, 2025
I'd change it to:
otherwise the suggestion is fine.
Rollup merge of rust-lang#140272 - Kivooeo:new-fix-four, r=est31
Rollup merge of rust-lang#140272 - Kivooeo:new-fix-four, r=est31
Rollup merge of rust-lang#140272 - Kivooeo:new-fix-four, r=est31
Unrolled build for rust-lang#140272
mcandre commentedon Jan 3, 2026
I thought that Rust recently added the ability to chain let matching?
est31 commentedon Jan 4, 2026
@mcandre I suppose you came here because you googled the error message that this issue added.
To answer your question, the let chain matching that stabilized in 1.88.0 in June 2025 is about chaining via
&&. Chaining via||is not supported and I am not aware of any plans to add that in the future. In any case, this issue about improving an error message wouldn't be a place to discuss that. Maybe a thread on internals.rust-lang.org ?