2013-03-15 19:24:24 +00:00
|
|
|
// Test that we detect nested calls that could free pointers evaluated
|
|
|
|
// for earlier arguments.
|
|
|
|
|
2021-08-25 00:39:40 +00:00
|
|
|
|
2014-05-06 01:56:44 +00:00
|
|
|
|
2015-01-08 11:02:42 +00:00
|
|
|
fn rewrite(v: &mut Box<usize>) -> usize {
|
2021-08-25 00:39:40 +00:00
|
|
|
*v = Box::new(22);
|
2013-03-15 19:24:24 +00:00
|
|
|
**v
|
|
|
|
}
|
|
|
|
|
2015-01-08 11:02:42 +00:00
|
|
|
fn add(v: &usize, w: usize) -> usize {
|
2013-03-15 19:24:24 +00:00
|
|
|
*v + w
|
|
|
|
}
|
|
|
|
|
|
|
|
fn implicit() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut a: Box<_> = Box::new(1);
|
2013-03-15 19:24:24 +00: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 23:35:15 +00:00
|
|
|
&*a,
|
2013-03-15 19:24:24 +00:00
|
|
|
rewrite(&mut a)); //~ ERROR cannot borrow
|
|
|
|
}
|
|
|
|
|
|
|
|
fn explicit() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let mut a: Box<_> = Box::new(1);
|
2013-03-15 19:24:24 +00:00
|
|
|
add(
|
|
|
|
&*a,
|
|
|
|
rewrite(&mut a)); //~ ERROR cannot borrow
|
|
|
|
}
|
|
|
|
|
2013-09-24 00:20:36 +00:00
|
|
|
fn main() {}
|