Skip to content

Wrong suggestion for slice patterns when using let-else statement #92069

Closed
@spaarmann

Description

@spaarmann

Given the following code: Playground link

#![feature(let_else)]

fn main() {
    let v = vec![1, 2, 3];
    let [a, b, c] = v else {
        panic!();
    };
}

The current output is:

error[E0529]: expected an array or slice, found `Vec<{integer}>`
 --> src/main.rs:5:9
  |
5 |     let [a, b, c] = v else {
  |         ^^^^^^^^^ pattern cannot match with input type `Vec<{integer}>`
  |
help: consider slicing here
  |
5 ~     let [a, b, c] = v else {
6 +         panic!();
7 +     };[..]
  |

The [..] should be added to the v, not after the whole statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsF-let_elseIssues related to let-else statements (RFC 3137)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