]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-slice-pattern-element-loan-array.rs
Rollup merge of #67219 - jsgf:command-argv0-debug, r=joshtriplett
[rust.git] / src / test / ui / borrowck / borrowck-slice-pattern-element-loan-array.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; 4]) {
7     let [ref first, ref second, ..] = *s;
8     let [_, ref mut  second2, ref mut third, ..] = *s; //~ERROR
9     nop(&[first, second, second2, third]);
10 }
11
12 fn const_index_from_end_err(s: &mut [i32; 4]) {
13     let [.., ref fourth, ref third, _, ref first] = *s;
14     let [.., ref mut third2, _, _] = *s; //~ERROR
15     nop(&[first, third, third2, 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_begin2, ..] = *s; //~ERROR
22     nop(&[from_begin2, from_end1, from_end3, from_end4]);
23     let [_, _, _, ref mut from_begin3, ..] = *s; //~ERROR
24     nop(&[from_begin3, 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_end3, _,  _] = *s; //~ERROR
29     nop(&[from_begin0, from_begin1, from_begin3, from_end3]);
30 }
31
32 fn const_index_and_subslice_err(s: &mut [i32; 4]) {
33     let [ref first, ref second, ..] = *s;
34     let [_, ref mut tail @ ..] = *s; //~ERROR
35     nop(&[first, second]);
36     nop_subslice(tail);
37 }
38
39 fn const_index_and_subslice_from_end_err(s: &mut [i32; 4]) {
40     let [.., ref second, ref first] = *s;
41     let [ref mut tail @ .., _] = *s; //~ERROR
42     nop(&[first, second]);
43     nop_subslice(tail);
44 }
45
46 fn subslices_overlap(s: &mut [i32; 4]) {
47     let [_,  ref s1 @ ..] = *s;
48     let [ref mut s2 @ .., _, _] = *s; //~ERROR
49     nop_subslice(s1);
50     nop_subslice(s2);
51 }
52
53 fn main() {
54     let mut v = [1,2,3,4];
55     const_index_err(&mut v);
56     const_index_from_end_err(&mut v);
57     const_index_and_subslice_err(&mut v);
58     const_index_and_subslice_from_end_err(&mut v);
59     subslices_overlap(&mut v);
60 }