2015-01-08 21:54:35 +11:00
|
|
|
fn borrow<F>(v: &isize, f: F) where F: FnOnce(&isize) {
|
2012-04-26 16:02:01 -07:00
|
|
|
f(v);
|
|
|
|
}
|
|
|
|
|
2021-08-25 02:39:40 +02:00
|
|
|
|
|
|
|
|
2012-04-26 16:02:01 -07:00
|
|
|
fn box_imm() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let mut v: Box<_> = Box::new(3);
|
2014-07-07 16:35:15 -07:00
|
|
|
borrow(&*v,
|
2014-02-10 07:44:03 -05:00
|
|
|
|w| { //~ ERROR cannot borrow `v` as mutable
|
2021-08-25 02:39:40 +02:00
|
|
|
v = Box::new(4);
|
2014-02-10 07:44:03 -05:00
|
|
|
assert_eq!(*v, 3);
|
|
|
|
assert_eq!(*w, 4);
|
|
|
|
})
|
2012-04-26 16:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
}
|