Closed
Description
Currently, the compiler does not account for the fact that "by value" passing of ref-counted boxes is in fact a borrow. This can be fixed easily enough in borrowck (or, I imagine, in alias). In any case, I added an xfail'd test (by-val-and-by-move.rs) that demonstrates the problem. This test fails (note the environment variable RUST_POISON_ON_FREE---without that, the test may accidentally pass even though it is accessing a freed pointer).
// xfail-test
// exec-env:RUST_POISON_ON_FREE
fn it_takes_two(x: @int, -y: @int) -> int {
free(y);
#debug["about to deref"];
*x
}
fn free<T>(-t: T) {
}
fn main() {
let z = @3;
assert 3 == it_takes_two(z, z);
}