Skip to content

Regression on array pattern-matching #15104

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

Closed
renato-zannon opened this issue Jun 23, 2014 · 6 comments
Closed

Regression on array pattern-matching #15104

renato-zannon opened this issue Jun 23, 2014 · 6 comments

Comments

@renato-zannon
Copy link
Contributor

Until friday (commit 3047614) the following (very contrived) code compiled:

fn main() {
    println!("{}", count_members(&[1, 2, 3, 4]));
}

fn count_members(v: &[uint]) -> uint {
    match v {
        []         => 0,
        [_]        => 1,
        [_x, ..xs] => 1 + count_members(xs)
    }
}

With ca3e557, it fails with:

array_match.rs:9:5: 9:15 error: unreachable pattern
array_match.rs:9     [_x, ..xs] => 1 + count_members(xs)
                     ^~~~~~~~~~
error: aborting due to previous error

I'll try to bisect and get to a single commit

@alexcrichton
Copy link
Member

cc @jakub-, I think one of your recent patches fixed this, right?

@ghost
Copy link

ghost commented Jun 23, 2014

@alexcrichton Yeah but this looks different... looking!

@renato-zannon
Copy link
Contributor Author

My bisect ended up pointing f5e513b as the first bad commit. This should help narrowing down the problem, as it has a relatively small diff

@bstrie
Copy link
Contributor

bstrie commented Jun 23, 2014

I just noticed this as well. A more minimal test case:

fn main() {
    match &[1,2,3] {
        [] => (),
        [_] => (),
        [_, ..] => ()  // error: unreachable pattern
    }
}

Notably, the error vanishes if you remove the one-element pattern:

fn main() {
    match &[1,2,3] {
        [] => (),
        [_, ..] => ()  // works fine
    }
}

@ghost
Copy link

ghost commented Jul 2, 2014

This is fixed now.

@alexcrichton
Copy link
Member

Thanks @jakub-!

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 17, 2023
Skip mutable diagnostics on synthetic bindings

Fixes rust-lang/rust-analyzer#15099

We probabnly need to look into this in a more general manner in the future now that we desugar more things
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

3 participants