Skip to content

let_chains and typo of == to = produce bad diagnostic #97469

Closed
@estebank

Description

@estebank

I wrote code like

                            let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind 
                                && let [segment] = path.segments
                                && kw::SelfUpper = segment.ident.name
                            {

when I meant

                            let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind 
                                && let [segment] = path.segments
                                && kw::SelfUpper == segment.ident.name
                            {

and was confused by the rust-analyzer and rustc output:

error: `let` expressions are not supported here
    --> compiler/rustc_typeck/src/astconv/mod.rs:1812:48
     |
1812 | ...                   let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind 
     |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: only supported directly in conditions of `if` and `while` expressions
     = note: as well as when nested within `&&` and parentheses in those conditions

error: `let` expressions are not supported here
    --> compiler/rustc_typeck/src/astconv/mod.rs:1813:36
     |
1813 | ...                   && let [segment] = path.segments
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: only supported directly in conditions of `if` and `while` expressions
     = note: as well as when nested within `&&` and parentheses in those conditions

error[E0433]: failed to resolve: use of undeclared crate or module `kw`
    --> compiler/rustc_typeck/src/astconv/mod.rs:1814:36
     |
1814 | ...                   && kw::SelfUpper = segment.ident.name
     |                          ^^ use of undeclared crate or module `kw`

error[E0308]: mismatched types
    --> compiler/rustc_typeck/src/astconv/mod.rs:1812:48
     |
1812 |   ...                   let qself_res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind 
     |  __________________________________________^
1813 | | ...                       && let [segment] = path.segments
1814 | | ...                       && kw::SelfUpper = segment.ident.name
     | |_______________________________________________________________^ expected `bool`, found `()`
     |
help: you might have meant to use pattern matching
     |
1812 |                             let qself_res = if let let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind 
     |                                                +++

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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