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

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

15 lines
329 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 19:24:24 +00:00
let tail = match vec {
2019-07-07 23:47:46 +00:00
&[_a, ref tail @ ..] => &tail[0],
_ => panic!("foo")
2012-12-15 23:13:55 +00:00
};
tail //~ ERROR cannot return value referencing local variable `vec`
2012-12-15 23:13:55 +00:00
}
fn main() {
let fifth = a();
println!("{}", *fifth);
2012-12-15 23:13:55 +00:00
}