Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous suggestion to add a slice in pattern-matching #96103

Closed
tjhance opened this issue Apr 16, 2022 · 0 comments · Fixed by #96122
Closed

Erroneous suggestion to add a slice in pattern-matching #96103

tjhance opened this issue Apr 16, 2022 · 0 comments · Fixed by #96122
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tjhance
Copy link

tjhance commented Apr 16, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=44c555e3d1e880be0fcff214d82cfe75

struct Foo {
    v: Vec<u32>,
}

fn f(foo: &Foo) {
    match foo {
        Foo { v: [1, 2] } => { }
        _ => { }
    }
}

fn main() {
    
}

The current output is:

E0529: expected an array or slice, found `Vec<u32>`
 --> src/main.rs:7:18
  |
6 |     match foo {
  |           --- help: consider slicing here: `foo[..]`
7 |         Foo { v: [1, 2] } => { }
  |                  ^^^^^^ pattern cannot match with input type `Vec<u32>`

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

The suggestion to try writing foo[..] is erroneous and would cause a different type error ("cannot index into a value of type &Foo"). I believe the suggestion should be removed here.

@tjhance tjhance added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2022
@TaKO8Ki TaKO8Ki self-assigned this Apr 16, 2022
@bors bors closed this as completed in 036d200 Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants