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

Incorrect non-exhaustive matching for fixed length arrays #8311

Closed
stepancheg opened this issue Aug 5, 2013 · 3 comments
Closed

Incorrect non-exhaustive matching for fixed length arrays #8311

stepancheg opened this issue Aug 5, 2013 · 3 comments

Comments

@stepancheg
Copy link
Contributor

fn foo(p: [u8, ..4]) {
    match p {
        [a, b, c, d] => {},
    };
}

Compiler reports non-exhaustive matching:

/.../tmp3.rs:2:4: 4:5 error: non-exhaustive patterns: vectors of length 0 not covered
/.../tmp3.rs:2     match p {
/.../tmp3.rs:3         [a, b, c, d] => {},
/.../tmp3.rs:4     };
error: aborting due to previous error

It is not possible p to have size 0.

Fixed length vectors should also be allowed in let statements:

let [a, b, c] = [1, 2, 3]; // currently reports error: refutable pattern in local binding
stepancheg added a commit to stepancheg/rust that referenced this issue Aug 8, 2013
Code like this is fixed now:

```
fn foo(p: [u8, ..4]) {
    match p {
        [a, b, c, d] => {}
    };
}
```

Invalid constructors are not reported as errors yet:

```
fn foo(p: [u8, ..4]) {
    match p {
        [_, _, _] => {} // this should be error
        [_, _, _, _, _, .._] => {} // and this
        _ => {}
    }
}
```

Issue rust-lang#8311 is partially fixed by this commit. Fixed-length arrays in
let statement are not yet allowed:

```
let [a, b, c] = [1, 2, 3]; // still fails
```
@jaeminMoon
Copy link
Contributor

I tested this issue. No more bugs. I think we should closed this issue.

  • rust version : 0.8, 0.9 pre

@thestinger
Copy link
Contributor

The pull request states that it wasn't a full fix because let statements are still not covered.

@huonw
Copy link
Member

huonw commented Mar 4, 2014

Closing in favour of #7784.

@huonw huonw closed this as completed Mar 4, 2014
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 27, 2022
fix `needless_question_mark` not considering async fn

closes rust-lang#8277

changelog: [`needless_question_mark`] Fix FN on async functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants