2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-03-01 17:55:31 -06:00
|
|
|
fn mk_identity<T:Copy>() -> @fn(T) -> T {
|
|
|
|
let result: @fn(t: T) -> T = |t| t;
|
|
|
|
result
|
2012-03-24 23:24:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-03-01 17:55:31 -06:00
|
|
|
// type of r is @fn(X) -> X
|
2012-03-24 23:24:47 -05:00
|
|
|
// 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
|
2013-03-15 14:24:24 -05:00
|
|
|
*r(@mut 3) = 4; //~ ERROR cannot assign to const dereference of @ pointer
|
2012-03-24 23:24:47 -05:00
|
|
|
}
|