2013-03-15 14:24:24 -05:00
|
|
|
// Test that we detect nested calls that could free pointers evaluated
|
|
|
|
// for earlier arguments.
|
|
|
|
|
2021-08-24 19:39:40 -05:00
|
|
|
|
2014-05-05 20:56:44 -05:00
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
fn rewrite(v: &mut Box<usize>) -> usize {
|
2021-08-24 19:39:40 -05:00
|
|
|
*v = Box::new(22);
|
2013-03-15 14:24:24 -05:00
|
|
|
**v
|
|
|
|
}
|
|
|
|
|
2015-01-08 05:02:42 -06:00
|
|
|
fn add(v: &usize, w: usize) -> usize {
|
2013-03-15 14:24:24 -05:00
|
|
|
*v + w
|
|
|
|
}
|
|
|
|
|
|
|
|
fn implicit() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut a: Box<_> = Box::new(1);
|
2013-03-15 14:24:24 -05:00
|
|
|
|
|
|
|
// Note the danger here:
|
|
|
|
//
|
|
|
|
// the pointer for the first argument has already been
|
|
|
|
// evaluated, but it gets freed when evaluating the second
|
|
|
|
// argument!
|
|
|
|
add(
|
2014-07-07 18:35:15 -05:00
|
|
|
&*a,
|
2013-03-15 14:24:24 -05:00
|
|
|
rewrite(&mut a)); //~ ERROR cannot borrow
|
|
|
|
}
|
|
|
|
|
|
|
|
fn explicit() {
|
2021-08-24 19:39:40 -05:00
|
|
|
let mut a: Box<_> = Box::new(1);
|
2013-03-15 14:24:24 -05:00
|
|
|
add(
|
|
|
|
&*a,
|
|
|
|
rewrite(&mut a)); //~ ERROR cannot borrow
|
|
|
|
}
|
|
|
|
|
2013-09-23 19:20:36 -05:00
|
|
|
fn main() {}
|