2012-03-24 23:24:47 -05:00
|
|
|
fn mk_identity<T:copy>() -> fn@(T) -> T {
|
|
|
|
fn@(t: T) -> T { t }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// type of r is fn@(X) -> X
|
|
|
|
// for some fresh X
|
|
|
|
let r = mk_identity();
|
|
|
|
|
|
|
|
// @mut int <: X
|
|
|
|
r(@mut 3);
|
|
|
|
|
|
|
|
// @int <: X
|
|
|
|
//
|
2012-03-25 15:54:05 -05:00
|
|
|
// This constraint forces X to be
|
|
|
|
// @const int.
|
|
|
|
r(@3);
|
2012-03-24 23:24:47 -05:00
|
|
|
|
2012-03-25 15:54:05 -05:00
|
|
|
// Here the type check succeeds but the
|
|
|
|
// mutability check will fail, because the
|
|
|
|
// type of r has been inferred to be
|
|
|
|
// fn(@const int) -> @const int
|
2012-06-30 06:23:59 -05:00
|
|
|
*r(@mut 3) = 4; //~ ERROR assigning to dereference of const @ pointer
|
2012-03-24 23:24:47 -05:00
|
|
|
}
|