rust/tests/ui/borrowck/borrowck-vec-pattern-element-loan.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
803 B
Rust
Raw Normal View History

fn a<'a>() -> &'a [isize] {
let vec = vec![1, 2, 3, 4];
let vec: &[isize] = &vec;
2013-03-15 14:24:24 -05:00
let tail = match vec {
2019-07-07 18:47:46 -05:00
&[_, ref tail @ ..] => tail,
_ => panic!("a")
};
tail //~ ERROR cannot return value referencing local variable `vec`
}
fn b<'a>() -> &'a [isize] {
let vec = vec![1, 2, 3, 4];
let vec: &[isize] = &vec;
2013-03-15 14:24:24 -05:00
let init = match vec {
2019-07-07 18:47:46 -05:00
&[ref init @ .., _] => init,
_ => panic!("b")
};
init //~ ERROR cannot return value referencing local variable `vec`
}
fn c<'a>() -> &'a [isize] {
let vec = vec![1, 2, 3, 4];
let vec: &[isize] = &vec;
2013-03-15 14:24:24 -05:00
let slice = match vec {
2019-07-07 18:47:46 -05:00
&[_, ref slice @ .., _] => slice,
_ => panic!("c")
};
slice //~ ERROR cannot return value referencing local variable `vec`
}
fn main() {}