]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-slice-pattern-element-loan-array.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-slice-pattern-element-loan-array.rs
1 fn nop(_s: &[& i32]) {}
2 fn nop_subslice(_s: &[i32]) {}
3
4 fn const_index_err(s: &mut [i32; 4]) {
5     let [ref first, ref second, ..] = *s;
6     let [_, ref mut  second2, ref mut third, ..] = *s; //~ERROR
7     nop(&[first, second, second2, third]);
8 }
9
10 fn const_index_from_end_err(s: &mut [i32; 4]) {
11     let [.., ref fourth, ref third, _, ref first] = *s;
12     let [.., ref mut third2, _, _] = *s; //~ERROR
13     nop(&[first, third, third2, fourth]);
14 }
15
16 fn const_index_mixed(s: &mut [i32; 6]) {
17     let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s;
18
19     let [_, _, ref mut from_begin2, ..] = *s; //~ERROR
20     nop(&[from_begin2, from_end1, from_end3, from_end4]);
21     let [_, _, _, ref mut from_begin3, ..] = *s; //~ERROR
22     nop(&[from_begin3, from_end1, from_end3, from_end4]);
23
24     let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s;
25
26     let [.., ref mut from_end3, _,  _] = *s; //~ERROR
27     nop(&[from_begin0, from_begin1, from_begin3, from_end3]);
28 }
29
30 fn const_index_and_subslice_err(s: &mut [i32; 4]) {
31     let [ref first, ref second, ..] = *s;
32     let [_, ref mut tail @ ..] = *s; //~ERROR
33     nop(&[first, second]);
34     nop_subslice(tail);
35 }
36
37 fn const_index_and_subslice_from_end_err(s: &mut [i32; 4]) {
38     let [.., ref second, ref first] = *s;
39     let [ref mut tail @ .., _] = *s; //~ERROR
40     nop(&[first, second]);
41     nop_subslice(tail);
42 }
43
44 fn subslices_overlap(s: &mut [i32; 4]) {
45     let [_,  ref s1 @ ..] = *s;
46     let [ref mut s2 @ .., _, _] = *s; //~ERROR
47     nop_subslice(s1);
48     nop_subslice(s2);
49 }
50
51 fn main() {
52     let mut v = [1,2,3,4];
53     const_index_err(&mut v);
54     const_index_from_end_err(&mut v);
55     const_index_and_subslice_err(&mut v);
56     const_index_and_subslice_from_end_err(&mut v);
57     subslices_overlap(&mut v);
58 }