Skip to content

Destructuring slices #15305

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
pfalabella opened this issue Jul 1, 2014 · 4 comments
Closed

Destructuring slices #15305

pfalabella opened this issue Jul 1, 2014 · 4 comments

Comments

@pfalabella
Copy link
Contributor

The intention of the second arm of the match below is to match slices with one element only (in this case only the second element in vects should match).

    let vects= [&[1u, 2, 3], &[1], &[]];

    for &vec in vects.iter() {
        let msg= match vec {
            [] => format!("empty"),
            [a]  => format!("only one element: {}", a),
            [a, ..rest] => format!("many elements, first is {}, then there are {}", a, rest) // this is unreachable?
        };

However the compiler complains that the third arm is now unreachable.

The workaround is transforming the second arm in [a,..rest] if rest==[] but I was advised on the #rust IRC channel that the [a] should work and that this is a bug.

@alexcrichton
Copy link
Member

cc @jakub-, I think there's an issue open for this already? Perhaps #15104?

@ghost
Copy link

ghost commented Jul 2, 2014

@alexcrichton Yes. And a PR for it as well #15186. :-)

@ghost
Copy link

ghost commented Jul 2, 2014

This is fixed now.

@alexcrichton
Copy link
Member

Nice work @jakub-!

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 24, 2023
docs: Add example on how to change configuration options in Kate

closes rust-lang#15305
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

2 participants