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