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