]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-slice-pattern-element-loan-slice.rs
Add more tests for borrowck and dropck slice pattern handling
[rust.git] / src / test / ui / borrowck / borrowck-slice-pattern-element-loan-slice.rs
1 #![feature(slice_patterns)]
2
3 fn nop(_s: &[& i32]) {}
4 fn nop_subslice(_s: &[i32]) {}
5
6 fn const_index_err(s: &mut [i32]) {
7     if let [ref first, ref second, ..] = *s {
8         if let [_, ref mut  second2, ref mut third, ..] = *s { //~ERROR
9             nop(&[first, second, second2, third]);
10         }
11     }
12 }
13
14 fn const_index_from_end_err(s: &mut [i32]) {
15     if let [.., ref fourth, ref third, _, ref first] = *s {
16         if let [.., ref mut third2, _, _] = *s { //~ERROR
17             nop(&[first, third, third2, fourth]);
18         }
19     }
20 }
21
22 fn const_index_mixed(s: &mut [i32]) {
23     if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
24         if let [_, ref mut from_begin1, ..] = *s { //~ERROR
25             nop(&[from_begin1, from_end1, from_end3, from_end4]);
26         }
27         if let [_, _, ref mut from_begin2, ..] = *s { //~ERROR
28             nop(&[from_begin2, from_end1, from_end3, from_end4]);
29         }
30         if let [_, _, _, ref mut from_begin3, ..] = *s { //~ERROR
31             nop(&[from_begin3, from_end1, from_end3, from_end4]);
32         }
33     }
34     if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
35         if let [.., ref mut from_end2, _] = *s { //~ERROR
36             nop(&[from_begin0, from_begin1, from_begin3, from_end2]);
37         }
38         if let [.., ref mut from_end3, _,  _] = *s { //~ERROR
39             nop(&[from_begin0, from_begin1, from_begin3, from_end3]);
40         }
41         if let [.., ref mut from_end4, _, _, _] = *s { //~ERROR
42             nop(&[from_begin0, from_begin1, from_begin3, from_end4]);
43         }
44     }
45 }
46
47 fn const_index_and_subslice_err(s: &mut [i32]) {
48     if let [ref first, ref second, ..] = *s {
49         if let [_, ref mut tail @ ..] = *s { //~ERROR
50             nop(&[first, second]);
51             nop_subslice(tail);
52         }
53     }
54 }
55
56 fn const_index_and_subslice_from_end_err(s: &mut [i32]) {
57     if let [.., ref second, ref first] = *s {
58         if let [ref mut tail @ .., _] = *s { //~ERROR
59             nop(&[first, second]);
60             nop_subslice(tail);
61         }
62     }
63 }
64
65 fn subslices(s: &mut [i32]) {
66     if let [_, _, _, ref s1 @ ..] = *s {
67         if let [ref mut s2 @ .., _, _, _] = *s { //~ERROR
68             nop_subslice(s1);
69             nop_subslice(s2);
70         }
71     }
72 }
73
74 fn main() {
75     let mut v = [1,2,3,4];
76     const_index_err(&mut v);
77     const_index_from_end_err(&mut v);
78     const_index_and_subslice_err(&mut v);
79     const_index_and_subslice_from_end_err(&mut v);
80     subslices(&mut v);
81 }