2014-02-05 16:33:10 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2014-09-06 15:52:07 -05:00
|
|
|
#![feature(advanced_slice_patterns)]
|
2015-03-26 20:34:27 -05:00
|
|
|
#![feature(slice_patterns)]
|
2014-09-06 15:52:07 -05:00
|
|
|
|
2013-03-11 05:53:41 -05:00
|
|
|
fn a() {
|
2015-01-25 15:05:03 -06:00
|
|
|
let x = [1];
|
2012-12-08 14:22:43 -06:00
|
|
|
match x {
|
2013-02-26 12:58:46 -06:00
|
|
|
[a] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-11 05:53:41 -05:00
|
|
|
|
|
|
|
fn b() {
|
2015-01-25 15:05:03 -06:00
|
|
|
let x = [1, 2, 3];
|
2013-03-11 05:53:41 -05:00
|
|
|
match x {
|
2014-09-06 17:23:55 -05:00
|
|
|
[a, b, c..] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
|
|
|
assert_eq!(b, 2);
|
2014-08-04 07:19:02 -05:00
|
|
|
let expected: &[_] = &[3];
|
|
|
|
assert_eq!(c, expected);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match x {
|
2014-09-06 17:23:55 -05:00
|
|
|
[a.., b, c] => {
|
2014-08-04 07:19:02 -05:00
|
|
|
let expected: &[_] = &[1];
|
|
|
|
assert_eq!(a, expected);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(b, 2);
|
|
|
|
assert_eq!(c, 3);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match x {
|
2014-09-06 17:23:55 -05:00
|
|
|
[a, b.., c] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
2014-08-04 07:19:02 -05:00
|
|
|
let expected: &[_] = &[2];
|
|
|
|
assert_eq!(b, expected);
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(c, 3);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
match x {
|
|
|
|
[a, b, c] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
|
|
|
assert_eq!(b, 2);
|
|
|
|
assert_eq!(c, 3);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 17:19:19 -05:00
|
|
|
fn c() {
|
2015-01-25 15:05:03 -06:00
|
|
|
let x = [1];
|
2013-08-08 17:19:19 -05:00
|
|
|
match x {
|
2014-10-09 14:17:22 -05:00
|
|
|
[2, ..] => panic!(),
|
2013-11-28 14:22:53 -06:00
|
|
|
[..] => ()
|
2013-08-08 17:19:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn d() {
|
2015-01-25 15:05:03 -06:00
|
|
|
let x = [1, 2, 3];
|
2013-08-08 17:19:19 -05:00
|
|
|
let branch = match x {
|
2015-01-25 15:05:03 -06:00
|
|
|
[1, 1, ..] => 0,
|
|
|
|
[1, 2, 3, ..] => 1,
|
|
|
|
[1, 2, ..] => 2,
|
2013-08-08 17:19:19 -05:00
|
|
|
_ => 3
|
|
|
|
};
|
|
|
|
assert_eq!(branch, 1);
|
|
|
|
}
|
|
|
|
|
2014-06-21 07:52:23 -05:00
|
|
|
fn e() {
|
2015-03-25 19:06:52 -05:00
|
|
|
let x: &[isize] = &[1, 2, 3];
|
2014-08-06 04:59:40 -05:00
|
|
|
match x {
|
2014-06-21 07:52:23 -05:00
|
|
|
[1, 2] => (),
|
|
|
|
[..] => ()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-11 05:53:41 -05:00
|
|
|
pub fn main() {
|
|
|
|
a();
|
|
|
|
b();
|
2013-08-08 17:19:19 -05:00
|
|
|
c();
|
|
|
|
d();
|
2014-06-21 07:52:23 -05:00
|
|
|
e();
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|