Use new 'p @ ..' syntax in tests.
This commit is contained in:
parent
891a736b02
commit
75da43dc87
36 changed files with 69 additions and 85 deletions
|
|
@ -11,7 +11,7 @@ fn foldl<T, U, F>(values: &[T],
|
|||
U: Clone+Debug, T:Debug,
|
||||
F: FnMut(U, &T) -> U,
|
||||
{ match values {
|
||||
&[ref head, ref tail..] =>
|
||||
&[ref head, ref tail @ ..] =>
|
||||
foldl(tail, function(initial, head), function),
|
||||
&[] => {
|
||||
// FIXME: call guards
|
||||
|
|
@ -28,7 +28,7 @@ fn foldr<T, U, F>(values: &[T],
|
|||
F: FnMut(&T, U) -> U,
|
||||
{
|
||||
match values {
|
||||
&[ref head.., ref tail] =>
|
||||
&[ref head @ .., ref tail] =>
|
||||
foldr(head, function(tail, initial), function),
|
||||
&[] => {
|
||||
// FIXME: call guards
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ pub fn main() {
|
|||
let x: &[isize] = &[1, 2, 3, 4, 5];
|
||||
if !x.is_empty() {
|
||||
let el = match x {
|
||||
&[1, ref tail..] => &tail[0],
|
||||
&[1, ref tail @ ..] => &tail[0],
|
||||
_ => unreachable!()
|
||||
};
|
||||
println!("{}", *el);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ fn a() {
|
|||
fn b() {
|
||||
let x = [1, 2, 3];
|
||||
match x {
|
||||
[a, b, c..] => {
|
||||
[a, b, c @ ..] => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
let expected: &[_] = &[3];
|
||||
|
|
@ -22,7 +22,7 @@ fn b() {
|
|||
}
|
||||
}
|
||||
match x {
|
||||
[a.., b, c] => {
|
||||
[a @ .., b, c] => {
|
||||
let expected: &[_] = &[1];
|
||||
assert_eq!(a, expected);
|
||||
assert_eq!(b, 2);
|
||||
|
|
@ -30,7 +30,7 @@ fn b() {
|
|||
}
|
||||
}
|
||||
match x {
|
||||
[a, b.., c] => {
|
||||
[a, b @ .., c] => {
|
||||
assert_eq!(a, 1);
|
||||
let expected: &[_] = &[2];
|
||||
assert_eq!(b, expected);
|
||||
|
|
@ -50,7 +50,7 @@ fn b() {
|
|||
fn b_slice() {
|
||||
let x : &[_] = &[1, 2, 3];
|
||||
match x {
|
||||
&[a, b, ref c..] => {
|
||||
&[a, b, ref c @ ..] => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
let expected: &[_] = &[3];
|
||||
|
|
@ -59,7 +59,7 @@ fn b_slice() {
|
|||
_ => unreachable!()
|
||||
}
|
||||
match x {
|
||||
&[ref a.., b, c] => {
|
||||
&[ref a @ .., b, c] => {
|
||||
let expected: &[_] = &[1];
|
||||
assert_eq!(a, expected);
|
||||
assert_eq!(b, 2);
|
||||
|
|
@ -68,7 +68,7 @@ fn b_slice() {
|
|||
_ => unreachable!()
|
||||
}
|
||||
match x {
|
||||
&[a, ref b.., c] => {
|
||||
&[a, ref b @ .., c] => {
|
||||
assert_eq!(a, 1);
|
||||
let expected: &[_] = &[2];
|
||||
assert_eq!(b, expected);
|
||||
|
|
@ -134,20 +134,6 @@ fn e() {
|
|||
assert_eq!(c, 1);
|
||||
}
|
||||
|
||||
fn f() {
|
||||
let x = &[1, 2, 3, 4, 5];
|
||||
let [a, [b, [c, ..].., d].., e] = *x;
|
||||
assert_eq!((a, b, c, d, e), (1, 2, 3, 4, 5));
|
||||
|
||||
let x: &[isize] = x;
|
||||
let (a, b, c, d, e) = match *x {
|
||||
[a, [b, [c, ..].., d].., e] => (a, b, c, d, e),
|
||||
_ => unimplemented!()
|
||||
};
|
||||
|
||||
assert_eq!((a, b, c, d, e), (1, 2, 3, 4, 5));
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
a();
|
||||
b();
|
||||
|
|
@ -155,5 +141,4 @@ pub fn main() {
|
|||
c();
|
||||
d();
|
||||
e();
|
||||
f();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@ pub fn main() {
|
|||
Foo { string: "baz" }
|
||||
];
|
||||
match x {
|
||||
[ref first, ref tail..] => {
|
||||
[ref first, ref tail @ ..] => {
|
||||
assert_eq!(first.string, "foo");
|
||||
assert_eq!(tail.len(), 2);
|
||||
assert_eq!(tail[0].string, "bar");
|
||||
assert_eq!(tail[1].string, "baz");
|
||||
|
||||
match *(tail as &[_]) {
|
||||
[Foo { .. }, _, Foo { .. }, ref _tail..] => {
|
||||
[Foo { .. }, _, Foo { .. }, ref _tail @ ..] => {
|
||||
unreachable!();
|
||||
}
|
||||
[Foo { string: ref a }, Foo { string: ref b }] => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue