2012-12-08 20:22:43 +00:00
|
|
|
struct Foo {
|
|
|
|
string: ~str
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
Fix incorrect non-exhaustive matching for fixed length vecs
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 #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
```
2013-08-07 22:07:24 +04:00
|
|
|
let x = ~[
|
2012-12-08 20:22:43 +00:00
|
|
|
Foo { string: ~"foo" },
|
|
|
|
Foo { string: ~"bar" },
|
|
|
|
Foo { string: ~"baz" }
|
|
|
|
];
|
|
|
|
match x {
|
2013-06-20 15:11:20 -04:00
|
|
|
[ref first, ..tail] => {
|
2013-03-28 18:39:09 -07:00
|
|
|
assert!(first.string == ~"foo");
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(tail.len(), 2);
|
2013-03-28 18:39:09 -07:00
|
|
|
assert!(tail[0].string == ~"bar");
|
|
|
|
assert!(tail[1].string == ~"baz");
|
2012-12-08 20:22:43 +00:00
|
|
|
|
|
|
|
match tail {
|
2013-08-17 08:37:42 -07:00
|
|
|
[Foo { _ }, _, Foo { _ }, .. _tail] => {
|
2013-09-19 15:04:03 +10:00
|
|
|
unreachable!();
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
2013-05-22 06:54:35 -04:00
|
|
|
[Foo { string: ref a }, Foo { string: ref b }] => {
|
|
|
|
assert_eq!("bar", a.slice(0, a.len()));
|
|
|
|
assert_eq!("baz", b.slice(0, b.len()));
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
|
|
|
_ => {
|
2013-09-19 15:04:03 +10:00
|
|
|
unreachable!();
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
2013-09-19 15:04:03 +10:00
|
|
|
unreachable!();
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|