1 //compile-flags: -Z borrowck=mir
3 #![feature(slice_patterns)]
5 fn nop(_s: &[& i32]) {}
6 fn nop_subslice(_s: &[i32]) {}
8 fn const_index_ok(s: &mut [i32]) {
9 if let [ref first, ref second, _, ref fourth, ..] = *s {
10 if let [_, _, ref mut third, ..] = *s {
11 nop(&[first, second, third, fourth]);
16 fn const_index_err(s: &mut [i32]) {
17 if let [ref first, ref second, ..] = *s {
18 if let [_, ref mut second2, ref mut third, ..] = *s { //~ERROR
19 nop(&[first, second, second2, third]);
24 fn const_index_from_end_ok(s: &mut [i32]) {
25 if let [.., ref fourth, ref third, _, ref first] = *s {
26 if let [.., ref mut second, _] = *s {
27 nop(&[first, second, third, fourth]);
32 fn const_index_from_end_err(s: &mut [i32]) {
33 if let [.., ref fourth, ref third, _, ref first] = *s {
34 if let [.., ref mut third2, _, _] = *s { //~ERROR
35 nop(&[first, third, third2, fourth]);
40 fn const_index_mixed(s: &mut [i32]) {
41 if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
42 if let [ref mut from_begin0, ..] = *s {
43 nop(&[from_begin0, from_end1, from_end3, from_end4]);
45 if let [_, ref mut from_begin1, ..] = *s { //~ERROR
46 nop(&[from_begin1, from_end1, from_end3, from_end4]);
48 if let [_, _, ref mut from_begin2, ..] = *s { //~ERROR
49 nop(&[from_begin2, from_end1, from_end3, from_end4]);
51 if let [_, _, _, ref mut from_begin3, ..] = *s { //~ERROR
52 nop(&[from_begin3, from_end1, from_end3, from_end4]);
55 if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
56 if let [.., ref mut from_end1] = *s {
57 nop(&[from_begin0, from_begin1, from_begin3, from_end1]);
59 if let [.., ref mut from_end2, _] = *s { //~ERROR
60 nop(&[from_begin0, from_begin1, from_begin3, from_end2]);
62 if let [.., ref mut from_end3, _, _] = *s { //~ERROR
63 nop(&[from_begin0, from_begin1, from_begin3, from_end3]);
65 if let [.., ref mut from_end4, _, _, _] = *s { //~ERROR
66 nop(&[from_begin0, from_begin1, from_begin3, from_end4]);
71 fn const_index_and_subslice_ok(s: &mut [i32]) {
72 if let [ref first, ref second, ..] = *s {
73 if let [_, _, ref mut tail..] = *s {
74 nop(&[first, second]);
80 fn const_index_and_subslice_err(s: &mut [i32]) {
81 if let [ref first, ref second, ..] = *s {
82 if let [_, ref mut tail..] = *s { //~ERROR
83 nop(&[first, second]);
89 fn const_index_and_subslice_from_end_ok(s: &mut [i32]) {
90 if let [.., ref second, ref first] = *s {
91 if let [ref mut tail.., _, _] = *s {
92 nop(&[first, second]);
98 fn const_index_and_subslice_from_end_err(s: &mut [i32]) {
99 if let [.., ref second, ref first] = *s {
100 if let [ref mut tail.., _] = *s { //~ERROR
101 nop(&[first, second]);
107 fn subslices(s: &mut [i32]) {
108 if let [_, _, _, ref s1..] = *s {
109 if let [ref mut s2.., _, _, _] = *s { //~ERROR
117 let mut v = [1,2,3,4];
118 const_index_ok(&mut v);
119 const_index_err(&mut v);
120 const_index_from_end_ok(&mut v);
121 const_index_from_end_err(&mut v);
122 const_index_and_subslice_ok(&mut v);
123 const_index_and_subslice_err(&mut v);
124 const_index_and_subslice_from_end_ok(&mut v);
125 const_index_and_subslice_from_end_err(&mut v);