]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-closures-use-after-free.rs
Rollup merge of #106797 - FawazTirmizi:dev/issues/104284, r=bjorn3
[rust.git] / tests / 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 struct Foo {
6   x: isize
7 }
8
9 impl Drop for Foo {
10   fn drop(&mut self) {
11     println!("drop {}", self.x);
12   }
13 }
14
15
16
17 fn main() {
18   let mut ptr: Box<_> = Box::new(Foo { x: 0 });
19   let mut test = |foo: &Foo| {
20     ptr = Box::new(Foo { x: ptr.x + 1 });
21   };
22   test(&*ptr); //~ ERROR cannot borrow `*ptr`
23 }