]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-vec-pattern-element-loan.rs
Rollup merge of #60520 - matklad:rustfmt-all-the-new-things, r=Centril
[rust.git] / src / test / ui / borrowck / borrowck-vec-pattern-element-loan.rs
1 #![feature(slice_patterns)]
2
3 fn a<'a>() -> &'a [isize] {
4     let vec = vec![1, 2, 3, 4];
5     let vec: &[isize] = &vec;
6     let tail = match vec {
7         &[_, ref tail..] => tail,
8         _ => panic!("a")
9     };
10     tail //~ ERROR cannot return value referencing local variable `vec`
11 }
12
13 fn b<'a>() -> &'a [isize] {
14     let vec = vec![1, 2, 3, 4];
15     let vec: &[isize] = &vec;
16     let init = match vec {
17         &[ref init.., _] => init,
18         _ => panic!("b")
19     };
20     init //~ ERROR cannot return value referencing local variable `vec`
21 }
22
23 fn c<'a>() -> &'a [isize] {
24     let vec = vec![1, 2, 3, 4];
25     let vec: &[isize] = &vec;
26     let slice = match vec {
27         &[_, ref slice.., _] => slice,
28         _ => panic!("c")
29     };
30     slice //~ ERROR cannot return value referencing local variable `vec`
31 }
32
33 fn main() {}