]> git.lizzy.rs Git - rust.git/blob - tests/ui/array-slice-vec/vec-tail-matching.rs
Rollup merge of #106715 - BoxyUwU:new_solver_triagebot, r=lcnr
[rust.git] / tests / ui / array-slice-vec / vec-tail-matching.rs
1 // run-pass
2
3 struct Foo {
4     string: &'static str
5 }
6
7 pub fn main() {
8     let x = [
9         Foo { string: "foo" },
10         Foo { string: "bar" },
11         Foo { string: "baz" }
12     ];
13     match x {
14         [ref first, ref tail @ ..] => {
15             assert_eq!(first.string, "foo");
16             assert_eq!(tail.len(), 2);
17             assert_eq!(tail[0].string, "bar");
18             assert_eq!(tail[1].string, "baz");
19
20             match *(tail as &[_]) {
21                 [Foo { .. }, _, Foo { .. }, ref _tail @ ..] => {
22                     unreachable!();
23                 }
24                 [Foo { string: ref a }, Foo { string: ref b }] => {
25                     assert_eq!("bar", &a[0..a.len()]);
26                     assert_eq!("baz", &b[0..b.len()]);
27                 }
28                 _ => {
29                     unreachable!();
30                 }
31             }
32         }
33     }
34 }