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