]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-slice-pattern-element-loan-slice-no-overlap.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-slice-pattern-element-loan-slice-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]) {
7     if let [ref first, ref second, _, ref fourth, ..] = *s {
8         if let [_, _, ref mut third, ..] = *s {
9             nop(&[first, second, third, fourth]);
10         }
11     }
12 }
13
14 fn const_index_from_end_ok(s: &mut [i32]) {
15     if let [.., ref fourth, ref third, _, ref first] = *s {
16         if let [.., ref mut second, _] = *s {
17             nop(&[first, second, third, 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_begin0, ..] = *s {
25             nop(&[from_begin0, from_end1, from_end3, from_end4]);
26         }
27     }
28     if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
29         if let [.., ref mut from_end1] = *s {
30             nop(&[from_begin0, from_begin1, from_begin3, from_end1]);
31         }
32     }
33 }
34
35 fn const_index_and_subslice_ok(s: &mut [i32]) {
36     if let [ref first, ref second, ..] = *s {
37         if let [_, _, ref mut tail @ ..] = *s {
38             nop(&[first, second]);
39             nop_subslice(tail);
40         }
41     }
42 }
43
44 fn const_index_and_subslice_from_end_ok(s: &mut [i32]) {
45     if let [.., ref second, ref first] = *s {
46         if let [ref mut tail @ .., _, _] = *s {
47             nop(&[first, second]);
48             nop_subslice(tail);
49         }
50     }
51 }
52
53 fn main() {
54     let mut v = [1,2,3,4];
55     const_index_ok(&mut v);
56     const_index_from_end_ok(&mut v);
57     const_index_and_subslice_ok(&mut v);
58     const_index_and_subslice_from_end_ok(&mut v);
59 }