]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-closures-use-after-free.rs
Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup
[rust.git] / src / test / ui / borrowck / borrowck-closures-use-after-free.rs
1 // Tests that a closure which mutates a local variable
2 // cannot also be supplied a borrowed version of that
3 // variable's contents. Issue #11192.
4
5 #![feature(box_syntax)]
6
7 struct Foo {
8   x: isize
9 }
10
11 impl Drop for Foo {
12   fn drop(&mut self) {
13     println!("drop {}", self.x);
14   }
15 }
16
17 fn main() {
18   let mut ptr: Box<_> = box Foo { x: 0 };
19   let mut test = |foo: &Foo| {
20     ptr = box Foo { x: ptr.x + 1 };
21   };
22   test(&*ptr); //~ ERROR cannot borrow `*ptr`
23 }