Skip to content

Let chain error message with || is confusing and verbose #140263

Closed
@ehuss

Description

@ehuss

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` statement which is confusing. I suppose this is technically correct (let is not allowed in an if with 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` expressions is confusing, since we are in an if expression.
  • The final note of note: `||` operators are not supported in let chain expressions shows 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.2

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.F-let_chains`#![feature(let_chains)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions