rust/src/test/run-pass/borrowck-borrow-from-expr-block.rs
Tim Chevalier 948172b93f Make comparisons between region pointers work
Region pointers were considered a scalar type, so compare_scalar_type would
get called to compare region pointers in trans. This would fail, since
compare_scalar_type has no case for region pointers.

Changed type_is_scalar to return false for region pointers. This had the side
effect of breaking casts to types of the form &T. To ameliorate that, I added
library functions ptr::assimilate (taking a &T to a *T) and ptr::to_uint
(taking a &T to a uint), both of which use reinterpret_cast.

While I was at it, I removed ty::type_has_resources, which is dead code.
2012-08-02 23:53:45 -07:00

18 lines
344 B
Rust

import ptr::to_uint;
fn borrow(x: &int, f: fn(x: &int)) {
f(x)
}
fn test1(x: @~int) {
// Right now, at least, this induces a copy of the unique pointer:
do borrow({*x}) |p| {
let x_a = ptr::addr_of(**x);
assert (x_a as uint) != to_uint(p);
assert unsafe{*x_a} == *p;
}
}
fn main() {
test1(@~22);
}