diff options
Diffstat (limited to 'tests/ui/borrowck/borrowck-vec-pattern-element-loan.rs')
-rw-r--r-- | tests/ui/borrowck/borrowck-vec-pattern-element-loan.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/borrowck/borrowck-vec-pattern-element-loan.rs b/tests/ui/borrowck/borrowck-vec-pattern-element-loan.rs new file mode 100644 index 000000000..cd853b833 --- /dev/null +++ b/tests/ui/borrowck/borrowck-vec-pattern-element-loan.rs @@ -0,0 +1,31 @@ +fn a<'a>() -> &'a [isize] { + let vec = vec![1, 2, 3, 4]; + let vec: &[isize] = &vec; + let tail = match vec { + &[_, 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; + let init = match vec { + &[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; + let slice = match vec { + &[_, ref slice @ .., _] => slice, + _ => panic!("c") + }; + slice //~ ERROR cannot return value referencing local variable `vec` +} + +fn main() {} |