2014-02-10 06:44:21 -06:00
|
|
|
// Tests that a closure which mutates a local variable
|
|
|
|
// cannot also be supplied a borrowed version of that
|
|
|
|
// variable's contents. Issue #11192.
|
|
|
|
|
|
|
|
struct Foo {
|
2015-01-08 04:54:35 -06:00
|
|
|
x: isize
|
2014-02-10 06:44:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Foo {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
println!("drop {}", self.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
|
|
|
|
2014-02-10 06:44:21 -06:00
|
|
|
fn main() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut ptr: Box<_> = Box::new(Foo { x: 0 });
|
2015-02-01 11:44:15 -06:00
|
|
|
let mut test = |foo: &Foo| {
|
2021-08-24 19:39:40 -05:00
|
|
|
ptr = Box::new(Foo { x: ptr.x + 1 });
|
2014-02-10 06:44:21 -06:00
|
|
|
};
|
2014-07-07 18:35:15 -05:00
|
|
|
test(&*ptr); //~ ERROR cannot borrow `*ptr`
|
2014-02-10 06:44:21 -06:00
|
|
|
}
|